Creating structure array using for loop

Hi everyone,
So I'm having some trouble populating a structure array. I found a very helpful tdms file converter on the file exchange that when I run for a data set, gives me a 1x1 structure. I have 1000 different data sets which I woud like to populate into a structure that is 1x1000. All data sets are the same size. I have done something very similare to this before but for a reason beyond me, I cannot get this to work. I have the script I am using below, any help would be much appreciated.
Num = 1000; %number of repeats
for i = 1:1000;
s3_data(i) = TDMS_getStruct(['20190919_s3_test_',num2str(i),'.tdms']);
end
The error I am recieving is as follows:
Subscripted assignment between dissimilar structures.
Error in Process_time_dependet (line 4)
s3_data(i) =
TDMS_getStruct(['20190919_s3_test_',num2str(i),'.tdms']);

3 件のコメント

thoughtGarden
thoughtGarden 2019 年 9 月 19 日
The error message doesn't match the line of code you are showing. Can you confirm that the code doesn't have a "1," in the line shown below?
s3_data(1,i) = TDMS_getStruct(['20190919_s3_test_',num2str(i),'.tdms']);
Stephen23
Stephen23 2019 年 9 月 19 日
編集済み: Stephen23 2019 年 9 月 20 日
"All data sets are the same size..."
Sure, but do the structures have exactly the same fields? If not, you will get that error:
>> S = struct('A',{1,2})
S =
1x2 struct array with fields:
A
>> S(3) = struct('B',3)
Subscripted assignment between dissimilar structures.
William Gray
William Gray 2019 年 9 月 20 日
Aplogies @thoughtGarden() I had copied an error message from a previous attempt, this has been updated. Thank you for the comment.
Thank you for the comment @Stephen Cobeldick, all structures have exactly the same fields as they are test repeats,

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2019 年 9 月 19 日

編集済み:

2019 年 9 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by