フィルターのクリア

How to construct a structure with cell data and doubles?

3 ビュー (過去 30 日間)
Pika
Pika 2012 年 1 月 25 日
I'm trying to create a structure using either the struct command or the cell2struct command. The fields that I want for the structure are in a 1x32 cell and ultimately ends up as a char. The values I want are 30001x32 doubles.
I first use num2cell and that seems to output as a cell array but the values are double and when I use cell2struct, I get errors.
Specifically, this is what I put in the command prompt: s = cell2struct(fields{:}, values{:},2); It gives me an error that a string is not a char or you can't use doubles.
I also tried: s = cell2struct(fields{1,1},values(:,1),2); i have values(:,1) because i want the entire column for that one field. This also gave me an error.
What should I do?

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 1 月 25 日
s = cell2struct(values, fields, 2);
  1 件のコメント
Pika
Pika 2012 年 1 月 26 日
Thanks. I tried it but it gives me separate struct for each value in the value array.
For example, I want it to be something like this:
s.time -> gives a 30001x1 array of time (0.0,0.1,0.2,etc)
But it gives me separate struct for each value:
s(1,1).time -> gives 0.0
s(2,1).time -> gives 0.1
s(3,1).time -> gives 0.2 etc

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

カテゴリ

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