Strings

2 次查看(过去 30 天)
M G
M G 2011-3-4
I am a newbie in MATLAB and I've got a stupid question ;) In a part of my program I need to add a part in a while loop to show the number of matrix. I want it to show this as the output:
For exapmple:
Matrix 1 = []
Matrix 2 = []
So as you see I want the same word "Matrix" in all outputs but the numbers in front should be changed. My problem is not how to work with loops, rather I do not know any command to put numbers (1, 2, 3, ...) in front of words (Matrix or any other string).
I very much appreciate helping me.

采纳的回答

David Young
David Young 2011-3-4
Mehdi, if you mean that you want to make variables Matrix1, Matrix2 etc. inside a loop, then I agree completely with Walter and Jan - it's just a bad idea.
However, if you mean that you want to print "Matrix 1", "Matrix 2" etc. then that's OK, and you could do something like this:
for k = 1:4
fprintf('Matrix %d = \n', k);
disp(rand(2)); % the matrix you want to print
end

更多回答(1 个)

Walter Roberson
Walter Roberson 2011-3-4
Please don't do that! Please see the FAQ
  1 个评论
Jan
Jan 2011-3-4
@Mehdi: This definitely the best possible help. Using a complicated method to create variables, which include the index in the name, demands for further complicated methods to access these variables later again. Voted: +1

请先登录,再进行评论。

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by