How do I display a plot based on the user input value?
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
rose mal
le 27 Fév 2021
Réponse apportée : Cris LaPierre
le 27 Fév 2021
The .mat file usage.mat contains yearBuilt, names, yearReconstruct, and score.
clear;
close all;
userInput=input("Please choose between the following numbers: 1,2 or 3.");
Test("usage.mat",userInput);
function Test(usage,userInput)
usage=load(usage);
figure();
if userInput==1
figure(1);
y=yearBuilt;
custom = 'v r';
z='Build Year';
else
figure(2);
if userInput == 2
y = yearReconstruct;
y(yearReconstruct==0)= NaN;
custom = '* b';
z='Reconstruction Year';
else
figure(3);
if userInput == 3
y=score;
custom ='. g';
z='Overall';
else
disp("Invalid input value, input must be either 1, 2, or 3");
end
end
end
hold on
x=names;
plot(y,custom,'Markersize',10,'lineWidth',2,'LineStyle','none');
xlabel('output');
ylabel(z);
grid on
set(gca,'xticklabel',x.')
xtickangle(-45);
end
My code keeps displaying empty graphs or multiple empty graphs.
0 commentaires
Réponse acceptée
Cris LaPierre
le 27 Fév 2021
You do not appear to have a variable yearBuilt. If this is part of your mat file, note that the syntax you use to load it loads it to a structure names usage.
Try using dot notation to access your variables.
y=usage.yearBuilt;
One comment about your plot inputs. These two settings do opposite things. You only need one or the other. LineStyle can also be set to 'none' by not specifying a style in the linespec input (your variable custom).
'lineWidth',2,'LineStyle','none'
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!