extract every two rows from the data

1 Ansicht (letzte 30 Tage)
cool dave
cool dave am 25 Nov. 2013
Beantwortet: Image Analyst am 25 Nov. 2013
Hi all,
i would like to inquire for possible solutions for my problem.
for example if i have a set of data (10x1 matrix):
1
2
3
4
5
6
7
8
9
10
i want to extract every two rows to do multiplication with a 5x1 matrix:
1
2
3
4
5
how can i do that ? my final results should be:
1
2
6
8
15
18
28
32
45
50
i made attempt to acquire a solution but i don't think i did it correctly.
r=[1;2;3;4;5];
m=size(data,1); i=1:2:m; j=2:2:m; n=[data(i) data(j)];
results=r.*n;
many thanks :)
  1 Kommentar
Sean de Wolski
Sean de Wolski am 25 Nov. 2013
I'm not clear how you got the final results. From the explanation I would've expected:
1*1
2*3
3*5
4*7
5*9
or
((1:5).').*x(1:2:end);

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 25 Nov. 2013
Here's one possible solution:
data = [1;2;3;4;5;6;7;8;9;10]
m=[1;2;3;4;5]
% Use imresize() in the Image Processing Toolbox.
out = data .* imresize(m,[length(data),1],'nearest')

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing and Computer Vision finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by