converting a horizontal matrix to vertical

510 ビュー (過去 30 日間)
sama
sama 2015 年 5 月 1 日
回答済み: Image Analyst 2015 年 5 月 2 日
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 件のコメント
Joseph Cheng
Joseph Cheng 2015 年 5 月 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 日
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 日
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 日
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.

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by