0

I have a struct of 283 Area values and I want to copy the higher than 1000 values to a second struct with a for function. I have writen the code I need like this

Lbp = regionprops(Lblack, 'Area');
Lbp.Area;
[r,c]=size(Lbp);

B(r,c) = struct();


for d=1:r
    for g=1:c
          if Lbp(d).Area > 1000
              i=1;
              B(i)=Lbp(d);
              i=i+1;
          end
    end
end

I am getting this error Subscripted assignment between dissimilar structures. Even though the structs are the same size. I know that my syntax is wrong but I can not figure out how to syntax it in order to copy the fields to the second struct.

Adiel
  • 3,071
  • 15
  • 21
Kate
  • 53
  • 1
  • 1
  • 6

1 Answers1

0

It's because B and Lbp do not have the same fields. Try the following:

B(r,c) = struct('Area',[]);
AnonSubmitter85
  • 933
  • 7
  • 14
  • @Kate It works. Maybe you didn't clear `B` from your workspace before entering `B(r,c) = struct('Area',[]);`. If `B(r,c) = struct();` is still in memory, then you will get the same error as before. Try `clear B` first and then try again. – AnonSubmitter85 Jan 07 '18 at 21:23
  • It only saves the last value. And all the other fields are filled with []. – Kate Jan 07 '18 at 21:34
  • @Kate You need to initialize `i` outside of the loops. It is being reset to 1 every iteration. – AnonSubmitter85 Jan 07 '18 at 21:40
  • Oh my god, yes! It totally slipped my eyes. Thank you! – Kate Jan 07 '18 at 21:47