MATLAB: ‘Logical’ function to read 2 variables and output to a new variable

elseiffor loopfunctionlogicMATLABoperandsoutputwrite to variable

Hello Community,
I am having a novice moment here – difficulty in organising my function to do what I want. In short, I am trying to:
1. Read the data in 'a', AND
2. Read the data in 'b'
3. When they agree with the terms (a basic logical test)
4. A numerical count is recorded in the appropriate row/column of 'Imloc'
Example, if a(:,1) & b(:,1) == '1', then in IMloc(1,1) a count is recorded (or nothing if not). If a(:,2) & b(:,1) == '1' a count would be recorded at Imloc(1,2) etc.
Here is what code I have:
function [ Imloc ] = IMLocation( a, b )
% Preallocate Imloc matrix with zeros
Imloc = zeros(1,11);
% Set counter
numout = 0;
% Create storage for output vector
outvec = [];
% Run for the length of
for k=1:length(a,b)
if a(k)==1 && b(k)==1
numout = (numout + 1), 'Imloc',(1:1))
Imloc(outvec(numout))
elseif a(k)==2 && b(k)==1
numout = (numout + 1) 'Imloc',1:2))
Imloc(outvec(numout))
elseif a(k)==3 && b(k)==1
numout = (numout + 1) 'Imloc',1:3))
Imloc(outvec(numout))
% etc. etc. etc.
elseif a(k)==11 && b(k)==1
numout = (numout + 1) 'Imloc',1:11))
Imloc(outvec(numout))
else
end
end
So, can anyone make a suggestion as to what is going wrong as I am not doing very well with this!
Regards,
10B.

Best Answer

Sorry, I didn't see the previous response. Your dataset isn't complete, but presuming it is, then
d=a(b==1); % only the 1's count...
u=unique(d); % the unique values that are in a
n=hist(d,u); % count for each possible bin
Your header row or whatever is simply the vector u with the 'm' appended if want (altho you'll then have to use a cell array to hold both datatypes together, of course)...
>> cellstr(num2str(u,'%dm')).'
ans =
'1m' '2m' '5m' '6m'
>>
for the above (partial) dataset...