Problems using plot3

3 views (last 30 days)
Sergio
Sergio on 30 Jan 2024
Answered: Dyuman Joshi on 30 Jan 2024
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.
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

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 30 Jan 2024
As I have mentioned earlier in my answer to one of your questions, do not use the deprecated xlsread function.
Utilize the robust readmatrix/readtable instead -
in = readtable('FordFocusCMAX.xlsx')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
in = 72×4 table
x_rsm Mil Pris Var4 _____ _____ _________ __________ 7 3100 1.099e+05 {0×0 char} 7 6615 1.059e+05 {0×0 char} 6 5600 98500 {0×0 char} 8 3300 1.3e+05 {0×0 char} 8 3373 1.46e+05 {0×0 char} 8 4100 1.399e+05 {0×0 char} 3 10145 74500 {0×0 char} 4 8500 68900 {0×0 char} 7 6885 1.09e+05 {0×0 char} 5 6900 1.099e+05 {0×0 char} 7 4900 1.299e+05 {0×0 char} 7 6770 1.099e+05 {0×0 char} 9 1700 1.31e+05 {0×0 char} 6 10300 89900 {0×0 char} 7 5526 1.07e+05 {0×0 char} 7 3552 1.09e+05 {0×0 char}
As you want to plot the data without any lines in between, we can use scatter3 here -
%plot the data as a red asterisks
scatter3(in{:,1}, in{:,2}, in{:,3}, 'r*')
xlabel('Year');
ylabel('Mileage');
zlabel('Price');

More Answers (1)

Animesh
Animesh on 30 Jan 2024
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:

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!