필터 지우기
필터 지우기

plot based on Table

조회 수: 1 (최근 30일)
M Abedi
M Abedi 2021년 1월 31일
댓글: M Abedi 2021년 2월 3일
I have a table like this
id nodeName longitude Latitude
'0' 'Sydney1' '151.20732' '-33.86785'
'1' 'Brisbane2' '153.02809' '-27.46794'
'2' 'Canberra1' '149.12807' '-35.28346'
that contain id of Nodes, Nod names and geographical longitudes and Latitudes.
now i want to have graph that be ecording to longitude and Latitude and also show the nod names as label of Nodes in plot. but i cant.
  댓글 수: 3
M Abedi
M Abedi 2021년 2월 1일
NodeCell2=cell(NodNumber, 4);
for i=1:NodNumber
NodeCell2(i,1)=all_ids(i); %id
NodeCell2(i,2)=all_names(i); %name
NodeCell2(i,3)=all_longs(i); % longitude
NodeCell2(i,4)=all_lats(i); %latitude
end
figure(3);
%plot(lats,longs,nodes);
plot(NodeCell2(:,2),NodeCell2(:,3), NodeCell2(:,2));
i use this comands . NodeCell2 is my cell matrix. but i cant show it in graph. this code has such error:
Error using plot
Invalid first data argument
Error in mytest7 (line 185)
plot(NodeCell2(:,2),NodeCell2(:,3), NodeCell2(:,2));
i am new in using Matlab and i dont know it well.
Walter Roberson
Walter Roberson 2021년 2월 1일
NodeCell2 = cell{1,4};
NodeCell2{1} = str2double(all_ids);
NodeCell2{2} = categorical(all_names);
NodeCell2{3} = str2double(all_longs);
NodeCell2{4} = str2double(all_lats);
scatter(NodeCell2{3}, NodeCell2{4});
text(NodeCell2{3}, NodeCell2{4}, NodeCell2{1}); %you might need string(NodeCell2{1}))

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

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 2월 1일
My first suggestion is to not convert your data to a cell. If you want to store everything in a single variable, use a table.
all_ids={'0';'1';'2'};
all_names={'Sydney1';'Brisbane2';'Canberra1'};
all_longs={'151.20732';'153.02809';'149.12807'};
all_lats={'-33.86785';'-27.46794';'-35.28346'};
myTbl = table(str2double(all_ids),string(all_names),str2double(all_longs),str2double(all_lats),'VariableNames',["id","nodeName","Longitude","Latitude"])
myTbl = 3x4 table
id nodeName Longitude Latitude __ ___________ _________ ________ 0 "Sydney1" 151.21 -33.868 1 "Brisbane2" 153.03 -27.468 2 "Canberra1" 149.13 -35.283
You can't include text in your plot command. Use the text function. See this page for how to access data in a table.
plot(myTbl.Latitude,myTbl.Longitude,'^');
text(myTbl.Latitude,myTbl.Longitude,"\leftarrow " + myTbl.nodeName)
  댓글 수: 1
M Abedi
M Abedi 2021년 2월 3일
thanx alot

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by