Issue with cell during for loop operation

조회 수: 1 (최근 30일)
Turbulence Analysis
Turbulence Analysis 2022년 2월 4일
댓글: Turbulence Analysis 2022년 2월 4일
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
Turbulence Analysis 2022년 2월 4일
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
Benjamin Thompson 2022년 2월 4일
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
Benjamin Thompson 2022년 2월 4일
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
Turbulence Analysis 2022년 2월 4일
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