structure

1 view (last 30 days)
developer
developer on 12 Sep 2011
Hello, I have a structure that has got 20 values :
temp_q(j)=struct('ff' ,{temp_Q});
I have something like this
>> temp_q(1,1).ff{1,1}
ans =
0.0046 0.2417
>> temp_q(1,1).ff{2,1}
ans =
0.0844 0.9421
>> temp_q(1,1).ff{3,1}
ans =
0.2599 0.5752
>> temp_q(1,1).ff{4,1}
ans =
0.1818 0.8212
>> temp_q(1,1).ff{5,1}
ans =
0.1450 0.4509
>> temp_q(2,1).ff{1,1}
ans =
0.5499 0.6477
>> temp_q(2,1).ff{2,1}
ans =
0.3998 0.9561
>> temp_q(2,1).ff{3,1}
ans =
0.8693 0.6491
But i want to make it like this label it as
>> temp_q.Q1
ans =
0.0046 0.2417
0.0844 0.9421
0.2599 0.5752
0.1818 0.8212
0.1450 0.4509
>> temp_q.Q2
ans =
0.5499 0.6477
0.3998 0.9561
0.8693 0.6491
Thanks in advance
  11 Comments
developer
developer on 13 Sep 2011
Yes it works now thanks alot :)
Fangjun Jiang
Fangjun Jiang on 13 Sep 2011
Great! Now since the question has been answered. Please consider reading this post for hints on how to ask a better question. Please also accept the question to indicate that the solution is valid. Many of your questions were answered but not accepted.
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 12 Sep 2011
You mean like this?
temp_Q=1:20;
temp_q=struct('ff',mat2cell(temp_Q,1,repmat(1,20,1)))
  18 Comments
developer
developer on 13 Sep 2011
Please check it again if it makes some sense.
Fangjun Jiang
Fangjun Jiang on 13 Sep 2011
See comments in your question.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 12 Sep 2011
for K = 1:length(temp_q)
temp_Q.(sprintf('Q%d', K)) = temp_q(K).ff;
end

Categories

Find more on Structures in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!