こんにちはゲストさん。会員登録(無料)して質問・回答してみよう!

解決済みの質問

【MATLAB】複数stringのarray/vectorの格納方法

こんにちは。MATLABプログラミングで質問です。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> a = 'cat';b = 'dog'; c = 'pig';
>> list = [a;b;c]
list =
cat
dog
pig
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
とリスト化できますが、下の場合、
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> a = 'cat';b = 'dog'; c = 'pig';d = 'bird';
>> list = [a;b;c;d]
??? エラー ==> vertcat
CAT引数の次元が一致していません
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dの次元が違いますのでエラーが出ます。
これをまとめるには、
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> list(1).str = a;list(2).str = b;list(3).str = c;list(4).str = d;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
でエラーがでなく成功しますが、
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> list
list =
1x4 struct array with fields:
str
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
一括に表示できずに困っています。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
list =
cat
dog
pig
bird
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
と表示させるようなMATLAB string vectorの格納方法はあるでしょうか?

なお、最大文字数に合わせてBlankを入れるのは、
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
length(list(1,:))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
とした時に誤った回答が出ますので、むむむです。

投稿日時 - 2009-08-30 22:07:22

QNo.5249898

困ってます

質問者が選んだベストアンサー

cell型にすれば良いと思います。
list = {a;b;c;d}

投稿日時 - 2009-09-10 08:11:18

お礼

遅くなりましたが、ありがとうございました。これでいけました!

投稿日時 - 2009-11-20 01:42:54

ANo.1

このQ&Aは役に立ちましたか?

1人が「このQ&Aが役に立った」と投票しています

回答(1)

あなたにオススメの質問