How to run this loop and make sure the information from a struct is assigned as a simple m x n x k ? My loop is overwriting the information

1 view (last 30 days)
I am trying to have the N vector as an m x n x k extracting the information from a struct suite
but the loop here is being overwritten. How can I avoid the overwriting in this loop?
if isempty(locations) || nargin==2
locations = find([Suite(:).active]); %active locations [1 2 4 6]
end
for loc = 1:13
if Suite(loc).active
for i=locations
M=zeros(size(Suite(i).scani,1), size(Suite(i).scani,2), length(find([Suite(i).active])));
k=1:length(locations)
M(:,:,k)=Suite(i).scani;
N(:,:,k)=M
end
DDD1=N(:,:,1);
DDD2=N(:,:,2);
DDD3=N(:,:,3);
DDD4=N(:,:,4);
end
end
  2 Comments
Mitchell Thurston
Mitchell Thurston on 11 Dec 2021
It's kind of unclear what you're trying to do here, but I'm guessing you want to be doing "N(:,:,i)=" instead of "N(:,:,k)=" since k should be the same no matter which iteration you're on. There's a few other problems I think I see, but I'm not really sure what the code is trying to accomplish so I can't say for sure.
juan sanchez
juan sanchez on 11 Dec 2021
I have information stored in a suite where each location is able to store velocity in (rows indicating time, columns indicating heights). The only active locations are 1 2 4 and 6. However I want to extract that information from the suite so that I have it as a normal matlab matrix Velocity(rows,columns, pages) so that each page takes the location.
The length of location will give me the right order 1 2 3 4 as I wish the pages to be stored but the suite has the information in locations 1 2 4 and 6. I tried to do a double loop but the information is all being overwritten. Then the size of the first 2 locations has 15600 rows but the last two rows have a size of 20800 so preallocating is also an issue.

Sign in to comment.

Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!