How do I use scatter plot: To get the value of zsol for each case v2sol is 0.4(For example) in the following code. Thanks for the help.
%
zspan=[0,400];
v0mat = [1 0.01 1;1 0.05 1;1 0.1 1;1 0.2 1];
zsol = {};
v1sol = {};
v2sol = {};
v3sol = {};
for k=1:size(v0mat,1)
v0=v0mat(k,:);
[z,v]=ode45(@rhs,zspan,v0);
zsol{k}=z;
v1sol{k}=v(:,1);
v2sol{k}=v(:,2);
v3sol{k}=v(:,3);
end
for k=1:size(v0mat,1)
figure(1)
plot(v2sol{k},zsol{k},'g')
hold on
xlabel('Velocity,w')
ylabel('Height, z')
grid on
end
function parameters=rhs(z,v)
alpha=0.116;
db= 2*alpha-(v(1).*v(3))./(2*v(2).^2);
dw= (v(3)./v(2))-(2*alpha*v(2)./v(1));
dgmark= -(2*alpha*v(3)./v(1));
parameters=[db;dw;dgmark];
end

 채택된 답변

Star Strider
Star Strider 2018년 3월 27일

0 개 추천

Add this, after the code you posted:
for k1 = 1:length(v2sol)
zsol04(k1) = interp1(v2sol{k1}, zsol{k1}, 0.4)
end
figure
scatter(zsol04, ones(1,length(v2sol))*0.4, 'p')
grid

댓글 수: 6

Dereje
Dereje 2018년 3월 27일
It works thanks a lot!! To add last question: Do you think, is there a means to show it with like a bar?. Now the values lie in same axis.
Star Strider
Star Strider 2018년 3월 27일

I am not certain what you want.

See if the documentation on the bar (link) function (or related functions, linked to within or at the end of that page) will do what you want.

If they do not, please describe what you want in more detail.

Dereje
Dereje 2018년 3월 27일
What I meant to say is: I have different 4 results when v2sol is 0.4 as you did it in scatter. In my code v2sol which is 0.4 is not a constant, it came from different scenarios which I wanted to show like case 1, case 2, case 3 and case 4. Therefore, in the graph I wanted to show the relation between case 1 and the first v2sol, case 2 and the second v2sol ,...

I am still not certain what you want to do.

Try this:

for k1 = 1:length(v2sol)
    zsol04(k1) = interp1(v2sol{k1}, zsol{k1}, 0.4)
end
figure
scatter(zsol04, ones(1,length(v2sol))*0.4, 'p')
grid
figure
bar((1:length(v2sol)), zsol04)
xlabel('v_{2}sol')
ylabel('zsol_4')
Dereje
Dereje 2018년 3월 27일
Exactly, this is what I meant. You make my day!Thanks again.
Star Strider
Star Strider 2018년 3월 27일
As always, my pleasure!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 3월 27일

0 개 추천

plot(v2sol{k},zsol{k},'g*')
to use the * marker
When you specify a marker to plot() but do not specify a line type such as 'g-*' for using line type '-', then plot() will only put in the markers and not the lines connecting the points.

카테고리

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

태그

질문:

2018년 3월 27일

댓글:

2018년 3월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by