Problems using plot3
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sergio
el 30 de En. de 2024
Respondida: Dyuman Joshi
el 30 de En. de 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
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 30 de En. de 2024
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 comentarios
Más respuestas (1)
Animesh
el 30 de En. de 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:
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!