Store answers in multiple variables?

1 次查看(过去 30 天)
Hello,
I have a variable B which outputs about 100 cells. Assuming N = 4, how do I go about obtaining cell2mat(B(N(1)) in a new variable x_1, cell2mat(B(N(2)) in x_2, and so forth? Currently I am using:
for cnt = 1:N
hold on;
x = cell2mat(B(cnt));
end
Thanks in advance!
-- Jake
  2 个评论
Daniel Shub
Daniel Shub 2011-9-28
In general, you probably do not want to be doing this. Why do you want x1, x2, ... It is only going to lead to evil eval statements later.
Jake Bolanski
Jake Bolanski 2011-10-1
On a separate note, is there a function in MatLab that will allow me to detect colors within an image? I have broken down the image into a matrix via the imread() function. How can I go about detecting whether the leaf detected is green or yellow or so on? Thanks in advance.

请先登录,再进行评论。

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-9-28
"hold on" is for graphics. It has nothing to do your operation.
Depending on your cell array B, you may not need cell2mat. See this example:
B={rand(2),magic(2),rand(3),magic(3),rand(4),magic(4)};
[x1,x2,x3,x4]=B{2:5}
  4 个评论
Fangjun Jiang
Fangjun Jiang 2011-10-1
And this http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
Jake Bolanski
Jake Bolanski 2011-10-1
Wow, very very very helpful! Thanks a bunch! :D

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by