converting a horizontal matrix to vertical

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

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).

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2015년 5월 2일
편집: Stephen23 2015년 5월 2일

3 개 추천

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

추가 답변 (2개)

Star Strider
Star Strider 2015년 5월 2일

0 개 추천

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
Image Analyst
Image Analyst 2015년 5월 2일

0 개 추천

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.

카테고리

질문:

2015년 5월 1일

답변:

2015년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by