How can I vertically concatenate cells?

2 ビュー (過去 30 日間)
Nathan
Nathan 2019 年 5 月 24 日
編集済み: James Tursa 2019 年 5 月 24 日
I'm trying to vertically concatenate the output Nm so that I get an array column with alternating 'Long' and 'Short' based upon my input. I feel like this should be really simple to do, but I've been unable to find anything that works after a couple hours of searching. Any help would be much appreciated!
Ln = input('Maximal length? ');
if Ln >= 0.6
Nm = 'Long'
elseif Ln < 0.6
Nm = 'Short'
end
  3 件のコメント
James Tursa
James Tursa 2019 年 5 月 24 日
What is your desired output?
Nathan
Nathan 2019 年 5 月 24 日
I'm just trying to get something that lists "Long, Short, Short, Long, Short" ... etc. based upon my inputs. I need this to be in a vertical column within an array/matrix/whatever the word is (I'm really new to matlab)

サインインしてコメントする。

回答 (1 件)

James Tursa
James Tursa 2019 年 5 月 24 日
編集済み: James Tursa 2019 年 5 月 24 日
I don't have much of a clue what you really need, but maybe this will give you a start on the MATLAB cell array syntax (with the curly braces { }) that could be of use to you:
n = 10;
Nm = cell(n,1);
for k=1:n
Ln = input('Maximal length? ');
if Ln >= 0.6
Nm{k} = 'Long';
else
Nm{k} = 'Short';
end
end
disp(Nm)
Then downstream in your code you can get at the individual strings with the syntax Nm{k}
If you needed to append an addition entry, you could do it like this:
Nm{end+1} = 'Long';

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by