I have matrix A =[nx1] & B = [nx1] I want to combine them into C = [ nx2]

조회 수: 5 (최근 30일)
Rashid Hussein
Rashid Hussein 2017년 11월 3일
편집: Rashid Hussein 2017년 11월 4일
I tried to do plot ( A,B) But it showed me 2 lines in one plot
Because I wanted to make A as x-axis & B as y axis in plot

채택된 답변

Guillaume
Guillaume 2017년 11월 3일
The title of your question has nothing to do with the body of your question.
To answer your title:
C = [A, B];
To answer the body:
plot(A, B)
is indeed the correct syntax to plot B as y values and A as x values. If you get 2 lines in the legend, that would be because B has twice the numbers of rows or columns of A. If A and B are indeed both nx1, you cannot get two lines.
  댓글 수: 5
Guillaume
Guillaume 2017년 11월 4일
Do you realise how difficult you make it to help you? The title of your question had nothing to do with the body of the question, and now it turns out that neither had anything to do with your problem.
So all along, you weren't using plot(A, B) but plot([A, B]) which is not the same thing at all. plot([A, B]) is the same as plot((1:numel(A))', [A, B]) and will indeed plot two lines since you pass a matrix with two columns for the y values. What else would you expect.
But when I tried [...] It didn't work
Utterly. Useless. Statement. It didn't work, because you got an error? If so, what was the error?, because it didn't do what you expected? If so, what did you get and what did you expect?
Pks = foundpeaks (Data)
I am not aware of a function called foundpeaks in matlab. There is a findpeaks function in the signal processing toolbox. If you misspell function then yes, it is not going to work. Now, if that's what you were trying to do and A is indeed your x values, then passing [A, B] to findpeaks is indeed not going to work since as documented, the x value must be given as the second argument
pks = findpeaks(B, A);
Note that findpeaks has nothing to do with your plot. You don't need to plot anything for it to work.
Rashid Hussein
Rashid Hussein 2017년 11월 4일
편집: Rashid Hussein 2017년 11월 4일
Thank you and for the function name , then yes I misspelled the name here , anyway I have a clue of what I should do & thank you again sir .

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

추가 답변 (1개)

KL
KL 2017년 11월 3일
편집: KL 2017년 11월 3일
C = [A, B]
for plotting A against B, you are right,
plot(A,B)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by