data_array(:,1)= [1; 3; 4; 5; 7; 8];
data_array(:,2)= [4; 6; 12; 15; 3; 12];
color_array= [0 0.447 0.741; 0 1 1; 0 1 0; 1 0 1; 1 0 0; 1 0 1 ];
marker_type= ['o'; '.'; 'o'; '.'; 'o'; '.'];
size_array= [20;5;5;20;5;20];
Now i want to plot al this data of point with just one command and have tried with plot like this but it doesn't work
>>plot( data_array(:,1), data_array(:,2), mark_type, 'MarkerSize', size_array, 'Color', color_array)
How can i solve this problem? Thanks!

댓글 수: 4

madhan ravi
madhan ravi 2019년 1월 29일
scatter3() ?
Mai Le Thai
Mai Le Thai 2019년 1월 29일
편집: Mai Le Thai 2019년 1월 29일
Can you tell a little bit more about scatter3. I have tried but it doesn't work. I have also tried with scatter. It allow me to change the size and color at the markers but i can not change the marker type.
KSSV
KSSV 2019년 1월 29일
Why not a loop?
Mai Le Thai
Mai Le Thai 2019년 1월 29일
I am trying to vectorize the variable and just want to know another command, which is maybe more efficient

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

 채택된 답변

Luna
Luna 2019년 1월 29일
편집: Luna 2019년 1월 29일

0 개 추천

Hi Mai,
arrayfun gives you what you expected. Check my comments and read more about the function link is here: arrayfun
As KSSV mentioned above I put for loop also in the last part. Both gives the same result.
scatter3 gives you a 3-dimensional plot so you must have (x,y,z) axis datas as input to use that but you have only x and y axis data. Here is the link about scatter3 function you can see examples also: scatter3
% definitions
data_array(:,1)= [1; 3; 4; 5; 7; 8];
data_array(:,2)= [4; 6; 12; 15; 3; 12];
color_array = [0 0.447 0.741; 0 1 1; 0 1 0; 1 0 1; 1 0 0; 1 0 1 ];
marker_type = ['o'; '.'; 'o'; '.'; 'o'; '.'];
size_array= [20;5;5;20;5;20];
% Your color array must be 6x1 size and each row you have 1x3 double:
color_array_new = {[0 0.447 0.741]; [0 1 1]; [0 1 0]; [1 0 1]; [1 0 0]; [1 0 1]};
%% Usage of arrayfun with plot function:
figure;
hold on;
hLine = arrayfun(@(a,b,c,d,e) plot(a(1),b(1),'Marker',c(1),'MarkerSize',d(1),'Color',e{1}),data_array(:,1),data_array(:,2),marker_type,size_array,color_array_new);
% hLine is the handle array of your line objects (6x1 array).
%%%%% OR %%%%%
% This can be done with for loop easily:
figure;
for i = 1:length(marker_type)
plot(data_array(i,1),data_array(i,2), marker_type(i), 'MarkerSize', size_array(i), 'Color', color_array(i,:));
hold on;
end

댓글 수: 2

Mai Le Thai
Mai Le Thai 2019년 1월 30일
Hi Luna,
Your solution is great. With the for loop I got myself too, but the arrayfun command is what i want to know. Many thanks!
Luna
Luna 2019년 1월 30일
Your welcome :)

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

추가 답변 (0개)

카테고리

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

제품

릴리스

R2018b

태그

질문:

2019년 1월 29일

댓글:

2019년 1월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by