converting a horizontal matrix to vertical
268 次查看(过去 30 天)
显示 更早的评论
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
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).
采纳的回答
更多回答(2 个)
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
0 个评论
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!