structure

1 次查看(过去 30 天)
developer
developer 2011-9-12
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 个评论
developer
developer 2011-9-13
Yes it works now thanks alot :)
Fangjun Jiang
Fangjun Jiang 2011-9-13
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

请先登录,再进行评论。

采纳的回答

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

请先登录,再进行评论。

更多回答(1 个)

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

类别

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