Finding integers between two vectors
Ältere Kommentare anzeigen
hi
im new in the matlab world
i have 2 vectors A and B size (1xM)
i need to find all the integers betwwen corresponding Columns and store the integers in cell arry
for example:
A= 4.54 5.11 9.58 15.04
B= 1.01 3.2 5.5 16.98
i need to create cell arry X that each column contains all the integers between the numbers in A and B columns (1.01-4.54 the integers 2,3,4 3.2-5.11 the integers 4,5... )
X=
2 4 6 16
3 5 7
4 8
9
how can i do it?
thanks
Akzeptierte Antwort
Weitere Antworten (1)
the cyclist
am 1 Sep. 2013
Bearbeitet: the cyclist
am 1 Sep. 2013
Here is a slick one-liner:
arrayfun(@(x,y) (ceil(min([x y])):floor(max([x,y])))',A,B,'UniformOutput',false)
Here is a straightforward way with a loop:
A = [4.54 5.11 9.58 15.04];
B = [1.01 3.2 5.5 16.98];
N = length(A);
X = cell(1,length(A));
for i = 1:N
hi = floor(max([A(i) B(i)]));
lo = ceil(min([A(i) B(i)]));
X{i} = (lo:hi)';
end
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!