Pull out data from a larger set with "isequal"
Show older comments
Hey Everyone, I'm not sure if this is an issue with me debugging or with my misunderstanding of the code but... I have a large data set called "names" which is the same length as "concat" but names is a cell and concat is a matrix. They are holding letter properties and numeric properties of some information respectively. What I want to do is copy data to another sheet that matches a name from the larger sheet. I have done this on different occasions in this script and had no problems. For some reason below I am only able to retrieve 10 matches, there are 190 matches that should be recognized. Is there something in the naming convention that doesnt allow matlab to see that these things are the same? could there be a "space' after or before a name messing this up? Excel was able to recognize these names as being the same, and hence my count of 190. What could be going wrong? I made myself an array called "namecheck" to see what names were passing through and if there was any patter. that is pasted below. Thank you very much, Max
Z = size(LC17);
num=Z(1,1);
Y=size(concat);
numx=Y(1,1);
numy=Y(1,2);
numz=Y(1,3);
LC17=table2array(LC17);
z=1;
LCconcat = zeros(1,numy,numz);
for i=1:num
for x=1:numx
B=names(x,1);
C=LC17(i,1);
if isequal(B,C)==1
LCconcat(z,:,:)=concat(x,:,:);
NameCheck(z,1)=B
NameCheck(z,2)=C
z=z+1;
end
end
end
{'LR11H-0.3-S402'} {'LR11H-0.3-S402'}
{'LR27-2.7-38E' } {'LR27-2.7-38E' }
{'LR29-0.0-22H' } {'LR29-0.0-22H' }
{'LR29-2.7-22H' } {'LR29-2.7-22H' }
{'LR31D-0.1-22H' } {'LR31D-0.1-22H' }
{'LR32E-0.1-3' } {'LR32E-0.1-3' }
{'LR4-0.9-21-A' } {'LR4-0.9-21-A' }
{'LR42-0.0-9' } {'LR42-0.0-9' }
{'LRB12-1748BTC' } {'LRB12-1748BTC' }
{'LRB19-2358BTC' } {'LRB19-2358BTC' }
2 Comments
KSSV
on 25 Oct 2018
IF you want to compare name which are strings use strcmp / Strcmpi. If you want to get common names from two sets have a look on ismember.
Stephen23
on 25 Oct 2018
" Is there something in the naming convention that doesnt allow matlab to see that these things are the same? could there be a "space' after or before a name messing this up?"
Possibly, but as you did not show us any of the names that fail your equivalency test, we have no way of knowing.
"What could be going wrong?"
As we don't have the data, at the moment the best we could say would be "they don't match". If you want more help with this, upload the name cell arrays in a .mat file, by clicking the paperclip button.
Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!