Issue with cell during for loop operation

1 次查看(过去 30 天)
Hi,
I am genrating cells of size 1 x 200 through for loop operation. Ideally, for each iteation I should get a array of size 100 x 3 double in each cell. However, as shown in the attached .mat file, the first array is 38 x 3. Over here, my intenstion is to insert zero into the missed entries, in such a way to make all the arrays of size 100 x 3.. Could someone help me with this ??
  2 个评论
Ankit
Ankit 2022-2-4
but you have more than ~1000x3 entries for the column 193 - 200? what you want to do for these cells?
Turbulence Analysis
Hi,
Sorry, that was a mistake in the previously attached file. Here, I have uploaded the new file.
For instance, if we consider the first entry i.e. Data1 {1,1} (in the attached file) where the array size is 38 x 3. Here, for instance, in the third column, the entries starting from 7, 8, 10 ..., here my goal is insert zero for the missing no's i.e. for 1 to 6.. likewise for all the missing no's in the third column... In this way, the third column will have no's to 1 to 100 and size of all the entries will be uniform i.e. 100 x 3..
Hope this helps!!

请先登录,再进行评论。

回答(1 个)

Benjamin Thompson
You can always copy a cell into a temp array, add zeros to increase array size, then write it back to the cell array:
temp = Data{1};
Data{1} = zeros(100,3);
size(temp)
temp((size(temp,1)+1):100,:) = 0;
Data{1} = temp;
size(Data{1})
  2 个评论
Benjamin Thompson
This is even easier and more efficient:
>> size(Data{7})
ans =
50 3
>> Data{7}((size(Data{7},1)+1):100,:) = 0;
>> size(Data{7})
ans =
100 3
Turbulence Analysis
Thanks.
However, the idea is to insert zero entry into the second column with respect to the missing number in the third colum.. As shown in the attached figure..
In this the third column always have numbers starting from 1 to 100 without any discontinuties, so the size will be 100 x 3

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by