Hi, I'm a bigginer and what I need is too specific.
I need to plot a graph that looks exaclty like this:
I have a h vector of size 4. a matrix X of size 4x39 and a matrix f(x) of size 4x39.
each line represents the ploting of row i in matrix X with corresponding row i in matrix f(x) for h(i).
Can someone please tell me how to plot this?
Thank you

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 12일
편집: Ameer Hamza 2020년 11월 12일

1 개 추천

Something like this
X; % 4x39
f; % 4x39
h; % 4x1
plot(X.', f.')
xlabel('x')
ylabel('(approximate) f(x)')
legend_strs = compose('Approximate f with h=%.2f', h)
legend(legend_strs)

댓글 수: 6

danielle sisserman
danielle sisserman 2020년 11월 14일
Ameer, Thank you! this is almost exactly what I need. My graph now looks like this:
The sharp staright lines are there because the X matrix is 4x39 but only the 39th row (represented by the purpule line in the graph) has 39 elements. the other rows are shorted. but in order to define the matrix I had to fill on the empty cells with zeros.
so, if row i in X has 39 values and row j has 39-n values and the n last cells in the row are zeros, how can I not plot all the zeros in my graph?
Thank you
Ameer Hamza
Ameer Hamza 2020년 11월 14일
I didn't understand it correctly. Can you share your data in a .mat file?
danielle sisserman
danielle sisserman 2020년 11월 14일
Yes! thank you.
I have two variables in F_X_data.mat.
U is equivalent to f in your above answer. and X_in is equivalent to X.
row i in X_in is the x axis of line i. and row i in U is the y axis of line i.
as you can see, all of the rows (in both X_in and U) have the same length. But, that is only because I initialized the matrices with zeros.
If row i has non zero values in it's first n cells, then the rest of the row is filled with zeros. and that is what is causing these sharp straight lines to zero in my graph:
I need my graph to not "see" the zeros. and thus, not plot them.
How can I handle this issue?
Thank you
Just replace 0 with nan. They will not be visible in plot()
figure();
ax = axes();
hold(ax);
U(U==0) = nan;
X_in(X_in==0) = nan;
for i = 1:4
plot(X_in(i,:), U(i,:))
end
danielle sisserman
danielle sisserman 2020년 11월 16일
Thank you!
Ameer Hamza
Ameer Hamza 2020년 11월 16일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

제품

태그

질문:

2020년 11월 12일

댓글:

2020년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by