Why is this code identifying more than one result?

I have written a code which looks through a database and plots certain things at a time. As far as I can tell, having all of my logic checks individually produces the correct locations and number of elements, but when I put them together it tells me that I have more than one result.
para1 = unique([structure.para1].','rows','stable');
for i = 1:length(para1);
c1 = [structure.para1].'==para1(i);
para2 = unique([structure(c1).para2].','rows','stable');
if length(para2)>1;
hold on
for j = 1:length(para2);
c2 = [structure.para2].'==para2(j);
para3 = unique([structure(c1&c2).para3].','rows','stable');
for k = 1:length(para3);
c3 = [structure.para3].'==para3(k);
set1 = zeros(size(unique(structure(c1&c2&c3).data(:,1)),1),1);
set1(:) = structure(c1&c2&c3).para3;
xs = unique(structure(c1&c2&c3).data(:,1));
for m = 1:length(xs);
c4 = structure(c1&c2&c3).data(:,1)==xs(m);
qm(m) = max(structure(c1&c2&c3).data(c4,10));
end
scatter3(set1,unique(structure(c1&c2&c3).data(:,1)),qm);
clear set1
end
end
hold off
end
end
Calling 'structure(c1&c2&c3).data' brings up the specific data block I am looking for, and c4 does correctly logic the elements I am looking for, but when I call
qm(m) = max(structure(c1&c2&3).data(c4,10));
It returns, 'Expected one output from a curly brace or dot indexing expression, but there were 2 results.' Why is it suddenly looking at multiple data blocks. I suspect it has somehow identified the elements for all para3 values (my actual data has element numbers line up that way), but that makes no sense when c1&c2&c3 does properly identify the single data block I want.
PS if anybody has any better way of reducing this code to not be four for loops I'm open to hearing it.

4 Comments

I can generate both results seemingly with no reason ...
> [c1 c2 c3] % show what conditons vectors are
ans =
8×3 logical array
1 1 1
1 1 0
1 0 1
1 0 0
0 1 1
0 1 0
0 0 1
0 0 0
>> (c1&c2&3) % generates the seemingly wrong result
ans =
8×1 logical array
1
1
0
0
0
0
0
0
>> c1 & c2 % first piece...looks ok
ans =
8×1 logical array
1
1
0
0
0
0
0
0
>> ans&c3 % also ok
ans =
8×1 logical array
1
0
0
0
0
0
0
0
>> (c1&(c2&c3)) % group results
ans =
8×1 logical array
1
0
0
0
0
0
0
0
>> and(c1,and(c2,c3)) % functional form
ans =
8×1 logical array
1
0
0
0
0
0
0
0
>> c1&c2&c3 % back to original -- now it's ok!!??
ans =
8×1 logical array
1
0
0
0
0
0
0
0
>> (c1&c2&c3) % put the parentheses back...no change
ans =
8×1 logical array
1
0
0
0
0
0
0
0
>> whos c*
Name Size Bytes Class Attributes
c1 8x1 8 logical
c2 8x1 8 logical
c3 8x1 8 logical
...
>> [c1 c2 c3] % check haven't inadvertently changed data
ans =
8×3 logical array
1 1 1
1 1 0
1 0 1
1 0 0
0 1 1
0 1 0
0 0 1
0 0 0
>> max(structure(c1&c2&)).data(c4,10))
Expected one output from a curly brace or dot indexing expression, but there were 2 results.
>> max(structure(and(c1,and(c2,c3))).data(c4,10))
ans =
0
>>
I can't explain it, but looks like there's something flaky in the input parser with multiple operators in succession without an intermediate store operation.
I think this is a bug; don't see it documented can't write successive operators.
The code works for me in my tests in R2018a.
Which MATLAB version are you using?
max(structure(c1&c2&3).data(c4,10));
^^ not c3
I KNEW that couldn't be right but even while I found one instance I still couldn't get these old eyes to see it in the original...
Thanks, Stephen/Walter...

Sign in to comment.

 Accepted Answer

(c1&c2&3)
Has &3 as the last component, not &c3

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Asked:

on 30 Aug 2018

Commented:

dpb
on 31 Aug 2018

Community Treasure Hunt

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

Start Hunting!