For example my data is:
data =
[1000] @(x)x.^2 @sin [0.5]
[2000] @(x)1./x @cos [0.6]
I want to save data
to a text file or another. (data
is a cell
matrix). How can I achieve this?
For example my data is:
data =
[1000] @(x)x.^2 @sin [0.5]
[2000] @(x)1./x @cos [0.6]
I want to save data
to a text file or another. (data
is a cell
matrix). How can I achieve this?
If you want to save data for later usage withing Matlab all you need is this
save('filename','variables separated by spaces'); % to save specific variables
save('filename'); % to save all variables
if you want to load the variables to the workspace again, use the following
load('filename');
if you need to write data as a readable text file instead of binary data, then try to use fprintf
, almost usable the same way as C's fprintf
. I advise you to check the documentation
Here's a little example :
name = 'John';
age = 20;
enter code here
file = fopen('yourfilename.txt','w') % w option stantds for 'write' permission
fprintf(file,'My name is %s and I am %d', name, age);
fclose(file); % close it when you finish writing all data
I didn't really understand how is your data
matrix formatted. It doesn't seem to be correct matlab code.
Regards ;)
To get the string representation of an anonymous function use char:
S = cell(size(data,1),1);
for iRow = 1:size(data,1)
S{iRow}=sprintf('%d %s %s %d\n', ...
data{iRow,1}, char(data{iRow,2}), char(data{iRow,3}), data{iRow,2});
end
and then write S
to the output file.