フィルターのクリア

how to call string array in structures

4 ビュー (過去 30 日間)
vamshidhar Reddy Peruvala
vamshidhar Reddy Peruvala 2016 年 12 月 20 日
編集済み: Jan 2016 年 12 月 20 日
>> m = {'January' 'February' 'March' 'April' 'May' 'June' 'July' 'August' 'September' 'October' 'November' 'December' };
>> m(2) = struct('month',m(2),'date',2,'day', 10)
Error: *Conversion to cell from struct is not possible***
when i use the above code i am getting this error.
can someone please help me with this error and explain how to call string array in a struct.
  1 件のコメント
José-Luis
José-Luis 2016 年 12 月 20 日
編集済み: José-Luis 2016 年 12 月 20 日
What are you trying to achieve?
As it stands you are trying to replace m(2) with a struct, which is possible if you use curly braces {}. The question is why would you want to do that? What is your objective?

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

回答 (2 件)

KSSV
KSSV 2016 年 12 月 20 日
month = {'January' 'February' 'March' 'April' 'May' 'June' 'July' 'August' 'September' 'October' 'November' 'December' };
date = randsample(1:30,length(month)) ;
day = randsample(1:30,length(month)) ;
s = struct('month',month,'date',date,'day',day)

Jan
Jan 2016 年 12 月 20 日
編集済み: Jan 2016 年 12 月 20 日
The problem is, that you try to replace a cell by a struct:
m(2) = struct('month',m(2),'date',2,'day', 10)
^ ^
It looks suspicious, that "m(2)" appears on both sides. If this is really wanted, you can replace the cell element using the curly braces instead of the parenthesis:
m{2} = struct('month',m(2),'date',2,'day', 10)
^ ^
Perhaps you want "m{2}" on the right hand side also?

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by