Hey
I have a short question. In my excel file (Test) I have defined coordinates for 4 cities.
City x1 x2 x3
1 2 5 4
2 7 2 5
3 12 5 6
4 9 10 5
In this case each city is defined by 3 coordinates (3d). Now I would like to introduce an if condition to plot the coordinates. My goal is to plot the coordinates. When two coordinates are used the script look like this:
data = xlsread('Test.xlsx',1)dist = dist(data(:,2:3)') % how many coordinates are necessary to describe the location from one city
dist(dist==0) = infx1 = data(:,2)x2 = data(:,3)x3 = data(:,4)if ndims(data) == 2 plot(x1, x2, 'x')else ndims(data) == 3 plot3(x1, x2, x3, 'x') end
And when 3 coordinates are used the script looks like this:
data = xlsread('Test.xlsx',1)dist = dist(data(:,2:4)') % how many coordinates are necessary to describe the location from one citydist(dist==0) = infx1 = data(:,2)x2 = data(:,3)x3 = data(:,4)if ndims(data) == 2 plot(x1, x2, 'x')else ndims(data) == 3 plot3(x1, x2, x3, 'x') end
The problem in my code is that ndims(data) in both cases is 2.
I hope someone can help to solve my problem. In the second case the number of ndims(data) should be 3.
Best
Best Answer
Try this: