Storing values in cell instead of struct

조회 수: 2 (최근 30일)
Ayesha
Ayesha 2014년 5월 3일
편집: per isakson 2014년 5월 3일
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