Problems using plot3
1 次查看(过去 30 天)
显示 更早的评论
I have an xlsx file I'd like to print information from. I would like to read this data into MATLAB and plot how the price of (these) cars depends on both model year and mileage. I used first plot to see that, but I got an incomplete representation on how the price depends on both mileage and year. So I realized I need to look at plot3 instead.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1603806/image.png)
xlsread('FordFocusCMAX.xlsx')
plot3(ans)
xlabel('Year')
ylabel('Mileage')
zlabel('Price')
title('Price variation on Ford Focus')
but I got the error:
Error using plot3
Not enough input arguments
The idea is to plot this without any line connecting them, since there is no evolution connected to the price development, and mileage. But the necessary parameters to create only points in the plot can't help without this error being fixed.
It is strange, because there are three columns in the xlsx file, so is this related to xlsread ?
Thanks
0 个评论
采纳的回答
Dyuman Joshi
2024-1-30
As I have mentioned earlier in my answer to one of your questions, do not use the deprecated xlsread function.
in = readtable('FordFocusCMAX.xlsx')
%plot the data as a red asterisks
scatter3(in{:,1}, in{:,2}, in{:,3}, 'r*')
xlabel('Year');
ylabel('Mileage');
zlabel('Price');
0 个评论
更多回答(1 个)
Animesh
2024-1-30
Hi,
The xlread function by default returns numerical data in the first output argument, text data in the second, and a raw cell array that combines both in the third. If your Excel file contains only numerical data and no headers, you can capture the output directly into a variable.
Here's how you can read the data from the Excel file and plot it correctly using plot3, assuming that the file contains only numeric data and the columns are in the order: Year, Mileage, Price.
% Read the data from the Excel file
[data, text, raw] = xlsread('FordFocusCMAX.xlsx');
% Separate the data into variables for clarity
year = data(:, 1); % Assuming the first column is the year
mileage = data(:, 2); % Assuming the second column is the mileage
price = data(:, 3); % Assuming the third column is the price
% Plot the data using plot3
plot3(year, mileage, price, '.');
% Set the axis labels and title
xlabel('Year');
ylabel('Mileage');
zlabel('Price');
title('Price variation on Ford Focus');
% Adjust view angle for better visualization
view(3);
You can refer to the plot3 documentation for more details:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Price and Analyze Financial Instruments 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!