MATLAB Answers

matlab storing data using nested for loop

Asked by JoonHee Joh

JoonHee Joh (view profile)

on 14 Jan 2018
Latest activity Answered by Emmanouil Tzorakoleftherakis

Emmanouil Tzorakoleftherakis (view profile)

on 24 Jan 2018
here is my problem:
I have raw data which is 3D ARRAY with (x,y,t) where x,y are points and t is # of samples
I want to take signals (512 samples) from 51x51, total 2601 different points and add those signals so that i can take the average
Thus, I want an array of the dimension 2601x512(512x2601 will also do i guess) and later I am planning to use 'sum' so that i can get 1x512 data
Here is what I have tried:
for iii = 1:51
for jjj = 1:51
for kkk = 1:2601
new_sig(kkk,:)=uwpi(294+iii,274+jjj,:);
% uwpi is my raw data and (294,274) is my starting point
end
end
end
when i do this, i get 2601x512 matrix but every row is identical which is not possible
when I try:
for iii = 1:51
for jjj = 1:51
new_sig(iii*jjj,:)=uwpi(294+iii,274+jjj,:);
end
end
In this case, some rows of new_sig have only 0s (I think this happens because of iii*jjj term)
I've also tried to use squeeze command but wasn't really getting anywhere
Can anyone point me to the right direction?
If there is a better way to do this without nested for loop, that's fine too
Thank you

0 Comments

Sign in to comment.

1 Answer

Emmanouil Tzorakoleftherakis (view profile)

Answer by Emmanouil Tzorakoleftherakis

Emmanouil Tzorakoleftherakis (view profile)

on 24 Jan 2018

Hi JoonHee,
In line
new_sig(kkk,:)=uwpi(294+iii,274+jjj,:);
you are attempting to assign a comma-separated list to a 2D matrix. Try changing that to
new_sig(kkk,:)=permute(uwpi(294+iii,274+jjj,:),[1 3 2]);

0 Comments

Sign in to comment.