Storing values in cell instead of struct

2 次查看(过去 30 天)
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?

采纳的回答

per isakson
per isakson 2014-5-3
编辑:per isakson 2014-5-3
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 个评论
Ayesha
Ayesha 2014-5-3
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 2014-5-3
编辑:per isakson 2014-5-3
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by