MATLAB Answers

converting a horizontal matrix to vertical

731 views (last 30 days)
Hello. I am trying to convert a 100*2 matrix to 2*100 matrix. I appreciate if you give me any idea. The reason is I need to find the pick of negative data at second column, and I am using following code:
NEG=[find(E(:,1)<0) E(E(:,1)<0,1)];
so for using following code I need my matrix be 2*100
EE=findpeaks(NEG(:,2));
Thanks a lot.

  1 Comment

Joseph Cheng
Joseph Cheng on 1 May 2015
Wouldn't the transpose modifier (') work for you?
x= [1 2;3 4;5 6]'
turns out to be [1 3 5; 2 4 6]
also are you mixing your row and column? because if NEG is 2*100
EE=findpeaks(NEG(:,2));
then you're just finding peaks of 2*1 array (two rows 1 column).

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 2 May 2015
Edited: Stephen Cobeldick on 2 May 2015
Use transpose, which can also be written .'
>> A = [1,2;3,4;5,6;,7,8]
A =
1 2
3 4
5 6
7 8
>> A.'
ans =
1 3 5 7
2 4 6 8

  0 Comments

Sign in to comment.

More Answers (2)

Star Strider
Star Strider on 2 May 2015
I cannot follow what you are doing with findpeaks. If you want to find the troughs (opposite of the peaks) just negate the column of your ‘E’ matrix you want findpeaks to use. You do not need to create a row vector out of it first, or find the minima. Let findpeaks do all of that for you.
For Example:
x = linspace(0, 6*pi); % Create 100x2 Matrix
E = [sin(x)' cos(x')]; % Create 100x2 Matrix
[Pks,Idx] = findpeaks(-E(:,2)); % ‘findpeaks’ With Negative Argument
figure(1)
plot(x, E, x(Idx),E(Idx,2),'bp', 'MarkerSize',10)
grid

  0 Comments

Sign in to comment.


Image Analyst
Image Analyst on 2 May 2015
Your NEG is some weird array that is a row vector (a "linear index") of the vector of indexes where E is negative, followed by a row vector of the actual E values themselves. Why are the indexes there? You don't want to find peaks based on the index numbers , which, actually will be monotonically increasing so there won't be any peaks even if it did make sense. Secondly, since NEG is a row vector, the second column of it, which you pass into findpeaks() will be just a single number, which is the number of the second index where your signal goes negative. It doesn't make sense. With findpeaks() you can find both peaks and valleys. I suggest you read up on findpeaks and look at Star's example.

  0 Comments

Sign in to comment.

Sign in to answer this question.