index for max value and vector indexing vectorize

2 Ansichten (letzte 30 Tage)
student melaku fekadu
student melaku fekadu am 5 Mär. 2013
Hello all, I have two questions. I am dealing with both because I want to avoid using loop in order to save computation time. So I am looking for solutions which do not use loop.
1. I have two huge three dimensional matrices which I want to compare between. Here I am giving a short example.
x(:,:,1) =
3 7
6 8
x(:,:,2) =
6 7
4 8
x(:,:,3) =
9 7
5 1
and
y(:,:,1) =
5 6
7 2
y(:,:,2) =
4 9
7
y(:,:,2) =
1 5
3 6
First I want to find max values in x(:,:,1) which would be 8 and compare it with the max value in y(:,:,1) which would be 7; next, I find max value in x(:,:,2) which would be 8 and compare it with max value in y(:,:,2) which would be 9; and finally I go on finding max value in x(:,:,3) which would be 9 and compare it with the max value in which is 6. My goal is to find the index of the maximum value in each case in a vector, like
a =[2,2;
1,2;
1,1];
the first row in a 2,2 indicates the index (row and column) of 8 (the ma value between x(:,:,1) and y(:,:,1). The second row in a 1,2 indicates the index of 9 from my comparison of x(:,:,2) and y(:,:,2) and finally the last row 1,1 indicates the index of 9 from my comparison of x(:,:,3) and y(:,:,3). My question is how do I construct vector a without loop.
2. I have the following variables
x=[15 25; 13 22; 15 22];
s=x(:,1);
as=x(:,2);
k=zeros(3,44);
k(:,as-22+s-12+1:44)=(as-22:1:65-22-(s-12));
My objective is to fill inside k. I am not able to do so. If correctly done, I should get the following.
k =
Columns 1 through 21
0 0 0 0 0 0 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Columns 22 through 42
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
Columns 43 through 44
39 40
41 42
39 40
I appreciate any help.
Thanks, Melaku

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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