Use a cell array in a for loop
조회 수: 10 (최근 30일)
이전 댓글 표시
Hi,
I want to be able to loop through data in a nested loop and create an array of values each time I loop round, and store this array in a cell array.
My code is currently:
nrms_data = zeros(48,67); %empty list 48 rows and with 67 columns spaces
for i =(1:67) %this will circle through all the gathers
for j = (1:48)%this will cycle through all the traces in the data for the individual gather
trace_j = data{i}(:,j); % gives j'th trace of the gather_i
good_trace = data{17}(:,j);
NRMS = nrms(good_trace, trace_j);
nrms_data{i}(j)= NRMS;
I thought that this would store the value of NRMS as the j'th column in the cell array nrms_data but the error is
Cell contents assignment to anon-cell array object.
I'm unsure how else to do this. I want to be able to create an array of nrms values for each ith gather and each jth trace and then have a cell array that is 67 columns long with 48 rows.
댓글 수: 0
채택된 답변
Guillaume
2018년 1월 29일
Well yes, you declare nrms_data as a matrix of double, not a cell array. In addition, nrms_data{i}(j) access the scalar element at position j in the matrix of cell i, so that's not what you want.
nrms_data = cell(48, 67);
for i = 1:67
%...
nrms_data{i, j} = NRMS;
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!