Jump to content

Data sharing

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
denx

denx

    Newbie

  • Members
  • Pip
  • 4 posts
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?

#2
CygnetGames

CygnetGames

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
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.

#3
denx

denx

    Newbie

  • Members
  • Pip
  • 4 posts

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.


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
CygnetGames

CygnetGames

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
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:

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

end

Where 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
denx

denx

    Newbie

  • Members
  • Pip
  • 4 posts

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:

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

end

Where 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_*

Guest_Kaabi_*
  • Guests
I'm happy it all worked out.

#7
Chinmoy

Chinmoy

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 392 posts
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
denx

denx

    Newbie

  • Members
  • Pip
  • 4 posts

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


#9
Chinmoy

Chinmoy

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 392 posts
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/