How do you produce an empty plot if value is higher or lower than given user input value?

1 回表示 (過去 30 日間)
tommy sandler
tommy sandler 2021 年 2 月 28 日
回答済み: Walter Roberson 2021 年 2 月 28 日
The .mat file has data for years, names, yearReconstruct
clear;
close all;
% Part 1
userInput=input("Please choose between the following numbers: 1 or 2");
% Part 2
circuit("power.mat",userInput);
% Part 3 to 5 - function implementation for bridges & branches
function circuit(power,userInput)
power=load(power);
figure();
if userInput==1
y=power.years;
custom = 'v r';
z='Year';
else
if userInput == 2
y = power.yearReconstruct;
y(power.yearReconstruct==0)= NaN;
custom = '* b';
z='Reconstruction Year';
else
y=[];
custom=[];
disp("Invalid input value, input must be either 1 or 2");
end
end
end
hold on
x=power.names;
plot(y,custom,'Markersize',10,'lineWidth',2);
xlabel('voltage');
ylabel(z);
grid on
set(gca,'xticklabel',x.')
xtickangle(-45);
end
I keep getting an error and it still gives me part of a plot.

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 28 日
y=nan;
custom=nan;
If you want to produce an empty plot for that case. Your current code will not produce any plot for that case.

カテゴリ

Help Center および File ExchangeFeature Detection and Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by