Storing values in cell instead of struct

2 views (last 30 days)
Hello,
So I've been wondering about an alternate way to store a whole bundle of information as double instead of struct. This is what I did with struct and I just want to convert the datatype to double.
%Save Data information in a file
A(1).f3=f3;
A(2).f2=f2;
A(3).fL3=fL3;
A(4).fH3=fH3;
A(5).f1_fH3=f1_fH3;
A(6).f2_fH3=f2_fH3;
A(7).ffL3=ffL3;
A(8).fHL3=fHL3;
A(9).fH2_fHL3=fH2_fHL3;
A(10).ff3=ff3;
A(11).f13=f13;
A(12).fH2_fLH3=fH2_fLH3;
A(13).fHH2=fHH2;
A(14).fH1_fHH2=fH1_fHH2;
A(15).fH2_fHH2=fH2_fHH2;
save(Route, 'A');
I'm doing this since I've to pass Route as an argument to a function which I realized does not accept struct and is giving me the error while performing logic and arithmetic operations. Any suggestions?

Accepted Answer

per isakson
per isakson on 3 May 2014
Edited: per isakson on 3 May 2014
Try something like
save( Route, '-regexp', '^f\w*\d$' );
this should save all variables, the name of which start with "f" and ends with a number. Or did I miss your question?
.
"convert the datatype to double" . f2, f3, etc. are they not already double? double(f3) converts to double.
.
"values in cell instead"
A = cell( 15, 1 );
A(1) = {f3};
A(2) = {f2};
A(3) = {fL3};
A(4) = {fH3};
A(5) = {f1_fH3};
A(6) = {f2_fH3};
A(7) = {ffL3};
A(8) = {fHL3};
A(9) = {fH2_fHL3};
A(10) = {ff3};
A(11) = {f13};
A(12) = {fH2_fLH3};
A(13) = {fHH2};
A(14) = {fH1_fHH2};
A(15) = {fH2_fHH2};
  2 Comments
Ayesha
Ayesha on 3 May 2014
Yes, you did but Thanks for replying. There is nothing wrong with the code I've mentioned above. All the variables are double. But when you execute them, 'Route' gets saved as struct. I just want to save it as double. What do you think?
per isakson
per isakson on 3 May 2014
Edited: per isakson on 3 May 2014
I think
save( Route, '-regexp', '^f\w*\d$' );
does that. Try
whos -file Route.mat
.
"'Route' gets saved as struct" . How do you know?
.
Maybe you should rephrase the question?

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!