0

I have compiled matlab file which displays large amount of numbers in an executable form as a console based application. I need to do further computation on the output of the executable in php. Is the output of the executable console based application in ASCII or numeric format?How can I convert the ASCII output in numeric format to do further computation on it in php?

I am using disp(variable) to display the output. The output is in the form.

    (1,1) 0.1424

(2,1) 0.0117 (3,1) 0.0000 (4,1) 0.0000 (5,1) 0.0677 (6,1) 0.0000 (7,1) 0.5308 (8,1) 0.0077 (9,1) 0.0512 (10,1) 0.0118 (11,1) 0.0001 (12,1) 0.1764

(114,1) 0.4564 (203,1) 0.2962 (250,1) 0.2474

Columns 1 through 7

0.1373 0.0414 0.0541 0.1342 0.5606 0.5293 0.1652

Columns 8 through 14

0.0341 0.0396 0.0633 0.0778 0.0289 0.0654 0.0752

Columns 15 through 21

0.3055 0.4602 0.0631 0.0360 0.0188 0.0497 0.0228

Columns 22 through 28

0.0294 0.0373 0.0734 0.3148 0.1703 0.0294 0.0057

Columns 29 through 35

0.0263 0.0382 0.0977 0.0396 0.1056 0.0781 0.1085

Columns 36 through 42

0.1537 0.0239 0.0154 0.0046 0.0121 0.0700 0.0171

Columns 43 through 49

0.0304 0.0551 0.2174 0.2594 0.1179 0.0355 0.0103

Columns 50 through 56

0.0084 0.0188 0.0025 0.0019 0.0219 0.1391 0.1527

Columns 57 through 63

0.0471 0.0313 0.0170 0.0557 0.0016 0.0044 0.0184

Columns 64 through 70

0.0194 0.2053 0.3206 0.1394 0.0208 0.0332 0.0658

Columns 71 through 77

0.0193 0.0073 0.0026 0.0223 0.1996 0.3017 0.0207

Columns 78 through 84

0.0168 0.0076 0.0038 0.1666 0.0278 0.0167 0.1070

Columns 85 through 91

0.3269 0.2546 0.0270 0.0026 0.0053 0.0079 0.0132

Columns 92 through 98

0.0059 0.0141 0.0205 0.1327 0.2656 0.0300 0.0049

Columns 99 through 105

0.0066 0.0228 0 0.0253 0.0622 0.0107 0.0792

Columns 106 through 112

0.0754 0.0157 0 0.0097 0.0229 0.1128 0.0549

user1583647
  • 1,227
  • 2
  • 24
  • 48

1 Answers1

0

Whenever a program produces "text" output, it will be as ASCII. You can usually pipe this text to a file or another process. Depending on the platform, something like > myfile.txt at the end of command will produce a file myfile.txt which contains all the output of your process (which might be matlab -nosplash myScript.m > myfile.txt. for instance).

Now the problem becomes one of reading a text file in with Python. You can refer to this earlier question for how to do that.

EDIT Note that it is quite easy to make your program write numbers to a file directly (rather than through the console). Here is a simple example:

A = 1:5;
fid = fopen('C:\mydir\mydata.dat', 'w');
fprintf(fid, '%d ', A);
fclose(fid);

This creates an array, opens a file for writing, writes the values to file, and closes the file. For testing, you could use

fid = 1;

instead - this will produce output to the console. I'm not sure if the fclose(fid) statement won't cause a problem if you do that...

Community
  • 1
  • 1
Floris
  • 45,857
  • 6
  • 70
  • 122
  • My program produces numeric output and not text. So is the output in ASCII form? I don't want to save the result in a text file but rather save it in a array in php for further comparison. I am using php and not Python. So any help in php? – user1583647 Apr 08 '13 at 02:45
  • How do you create your output? With a `fprintf(1,'%d',myVariable)` type of statement? Yes, that is text - ascii. If you do it some other way, please describe it by editing your question. – Floris Apr 08 '13 at 02:53
  • I have edited my question please look into it. Is there anyway to convert the output in array and use it in php? – user1583647 Apr 08 '13 at 03:18
  • Yes. Your problem is using `disp`. The output you show is all mangled. Please reduce it to something more readable. What is the output of `size(variable)`? The way it is displayed it almost looks like a sparse array, but then suddenly it becomes something else? – Floris Apr 08 '13 at 03:23
  • Okay I will have it reduce to something readable. I just want to know if the numeric output when changed to the console application does it change into ASCII form or not?Does it display the output in the same form that is given by the .m file? – user1583647 Apr 08 '13 at 04:11
  • Yes - if you write output to screen, you are actually writing ascii characters. The piece of code I wrote above should help you figure out what to do. This avoids getting lines of the form `Columns 15 to 21` showing up in the middle of your output, which makes parsing the output tricky (trickier than it needs to be, at least). – Floris Apr 08 '13 at 04:13
  • Okay, thank you. The problem is I have to run the exe 1000*1000 of times for different datas and don'n want to save it in a file cause it may take a lot of space in the server. I want to compare the output with the datas in the database and give the user a conclusion after that the data is of no use. So, is there any method that I can do this? – user1583647 Apr 08 '13 at 04:23
  • You could simply re-use the same file name for each pass - that will save considerable disk space. If you want to pass data from one process to another (matlab to python) without going through disk, the solution will depend on the OS you are using; it might require a rewrite of your question. – Floris Apr 08 '13 at 04:26