Hello, since i am new here, i hope i posted at the right category
I am using an application that is programmed with Sax Basic. What i want to do, is to plot data from this application with matlab, so i need to create a table of data that can be read by matlab. How could i do that?
Data sharing
Started by denx, May 31 2008 06:06 AM
8 replies to this topic
#1
Posted 31 May 2008 - 06:06 AM
|
|
|
#2
Posted 01 June 2008 - 04:04 AM
If your table is 2-dimensional (or you can convert it to 2-dimensions), you could use the matlab function dlmread.
Using this, you can write a text file from Sax Basic. Separate the table columns with any ascii character and the rows with newlines. Then use dlmread to read this file into matlab.
Using this, you can write a text file from Sax Basic. Separate the table columns with any ascii character and the rows with newlines. Then use dlmread to read this file into matlab.
#3
Posted 02 June 2008 - 08:03 AM
CygnetGames said:
If your table is 2-dimensional (or you can convert it to 2-dimensions), you could use the matlab function dlmread.
Using this, you can write a text file from Sax Basic. Separate the table columns with any ascii character and the rows with newlines. Then use dlmread to read this file into matlab.
Using this, you can write a text file from Sax Basic. Separate the table columns with any ascii character and the rows with newlines. Then use dlmread to read this file into matlab.
Thank you very much for your answer. This is what i am looking for.
The next question is how to export the data of an array from sax basic to a file, so that matlab will read them?
#4
Posted 03 June 2008 - 04:17 AM
The matlab function dlmread expects the file to be an ascii file with the rows of the matrix on separate lines and the columns of the matrix separated by any ascii character (you pass dlmread a parameter telling it which character). A standard character to use is a comma, in which case your file would look like the following:
There may be a sax basic function for turning your matrix into a string of this format, but it's easy to write your own. I don't know sax basic syntax, so I'll write it in pseudocode.
This code turns your matrix into a string, stored in output_string. You then write this string to a file (not sure of the syntax for this in sax basic).
In matlab, you then read in the file using dlmread, like so:
11,12,13,14,15,16,17,18 21,22,23,24,25,26,27,28 31,32,33,34,35,36,37,38 41,42,43,44,45,46,47,48
There may be a sax basic function for turning your matrix into a string of this format, but it's easy to write your own. I don't know sax basic syntax, so I'll write it in pseudocode.
// This code run by sax basic output_string = "" for i = 1 to matrix_rows for j = 1 to (matrix_columns - 1) output_string = output_string + matrix[i][j] + "," end output_string = output_string + matrix[i][matrix_columns] + newLine endWhere matrix is the sax basic matrix you want to give to matlab, matrix_rows is the number of rows in matrix, matrix_columns is the number of columns in matrix and newLine is a string containing a new line character - not sure what this will be in sax basic but in C-like languages it is "\n" and in visual basic it is vbNewLine.
This code turns your matrix into a string, stored in output_string. You then write this string to a file (not sure of the syntax for this in sax basic).
In matlab, you then read in the file using dlmread, like so:
// This code run by matlab
matlab_matrix = dlmread('filename', ',')
Where filename is the name of the file that you wrote from sax basic, and the ',' tells dlmread that the columns of the matrix are separated by commas. You would then have your matrix from sax basic sored in the variable matlab_matrix.
#5
Posted 05 June 2008 - 10:40 AM
CygnetGames said:
The matlab function dlmread expects the file to be an ascii file with the rows of the matrix on separate lines and the columns of the matrix separated by any ascii character (you pass dlmread a parameter telling it which character). A standard character to use is a comma, in which case your file would look like the following:
There may be a sax basic function for turning your matrix into a string of this format, but it's easy to write your own. I don't know sax basic syntax, so I'll write it in pseudocode.
This code turns your matrix into a string, stored in output_string. You then write this string to a file (not sure of the syntax for this in sax basic).
In matlab, you then read in the file using dlmread, like so:
11,12,13,14,15,16,17,18 21,22,23,24,25,26,27,28 31,32,33,34,35,36,37,38 41,42,43,44,45,46,47,48
There may be a sax basic function for turning your matrix into a string of this format, but it's easy to write your own. I don't know sax basic syntax, so I'll write it in pseudocode.
// This code run by sax basic output_string = "" for i = 1 to matrix_rows for j = 1 to (matrix_columns - 1) output_string = output_string + matrix[i][j] + "," end output_string = output_string + matrix[i][matrix_columns] + newLine endWhere matrix is the sax basic matrix you want to give to matlab, matrix_rows is the number of rows in matrix, matrix_columns is the number of columns in matrix and newLine is a string containing a new line character - not sure what this will be in sax basic but in C-like languages it is "\n" and in visual basic it is vbNewLine.
This code turns your matrix into a string, stored in output_string. You then write this string to a file (not sure of the syntax for this in sax basic).
In matlab, you then read in the file using dlmread, like so:
// This code run by matlab
matlab_matrix = dlmread('filename', ',')
Where filename is the name of the file that you wrote from sax basic, and the ',' tells dlmread that the columns of the matrix are separated by commas. You would then have your matrix from sax basic sored in the variable matlab_matrix.thank you very much
i managed it :)
#6
Guest_Kaabi_*
Posted 06 June 2008 - 12:33 PM
Guest_Kaabi_*
I'm happy it all worked out.
#7
Posted 06 June 2008 - 09:54 PM
What is sax basic? How good is it? Can you post an example code : to find a factorial?
God is real... unless declared an integer
my blog :: http://techarraz.com/
#8
Posted 07 June 2008 - 02:03 PM
Chinmoy said:
What is sax basic? How good is it? Can you post an example code : to find a factorial?
Its just a simple form of visual basic for applications, containing the basic libraries and i suppose that it accepts additional vb libraries. i am not a programmer or something so i don't know many details, but trying to find out what i have to learn fast cause the application i am using requires this knowledge.
for the factorial i haven't though of it but i suppose something like that would work(?):
Quote
Sub Main
F = factorial(10)
End Sub
Function factorial(x)
fact = 1
For i = 2 To x
fact = i*fact
Next i
factorial = fact
End Function
F = factorial(10)
End Sub
Function factorial(x)
fact = 1
For i = 2 To x
fact = i*fact
Next i
factorial = fact
End Function
#9
Posted 07 June 2008 - 08:27 PM
OK, so its' similar to VB. Heared of this language for the first time! Ill give it a try though.
God is real... unless declared an integer
my blog :: http://techarraz.com/


Sign In
Create Account

Back to top









