フィルターのクリア

How do I store cell arrays of the form name{n}.surname{s} to k(1)?

1 回表示 (過去 30 日間)
Aditi Bhalerao
Aditi Bhalerao 2017 年 3 月 6 日
編集済み: Jan 2017 年 3 月 7 日
Hi, I have cell arrays in the form of name{n}.surname{s}. I am want to store the all the names and surnames in a cell array such that k(1) will give the first name and surname, k(2) will give the second name and surname and so on. I am new to Matlab. Can anyone please help me out?
  2 件のコメント
Jan
Jan 2017 年 3 月 7 日
Does "name{n}.surname{s}" mean, that "name" is a cell array containing structs? Or should the "." be a ","?
Aditi Bhalerao
Aditi Bhalerao 2017 年 3 月 7 日
Yes, name is a cell array containing structs.

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

回答 (2 件)

Jan
Jan 2017 年 3 月 7 日
編集済み: Jan 2017 年 3 月 7 日
If the name and surname are two cell strings:
fullname = strcat(name, ' ', surname);
Now fullname{k} contains the full name. You do not need a loop, because strcat acceptes cell strings as inputs directly.

KSSV
KSSV 2017 年 3 月 7 日
N = 10 ;
name = cell(N,1) ;
surname = cell(N,1) ;
for i = 1:N
name{i} = randseq(randsample(1:10,1)) ; % some random char
surname{i} = randseq(randsample(1:10,1)) ; % some random char
end
k = cell(N,1) ;
for i = 1:N
k{i} = [name{i},' ',surname{i}] ;
end
Can be vectorised, as you are a beginner, I gave you solution with loop.
  1 件のコメント
Aditi Bhalerao
Aditi Bhalerao 2017 年 3 月 7 日
This worked out for me. Thank you very much!

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

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by