Clear Filters
Clear Filters

matlab storing data using nested for loop

1 view (last 30 days)
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

Answers (1)

Emmanouil Tzorakoleftherakis
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]);

Categories

Find more on 루프와 조건문 in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!