Compact way to plot multiple listdlg items depending on user input.
I want to find a way to write a compact script that requests user input on a listdlg box and plots a graph depending on the parameters chosen (could be multiple parameters). I am relatively new to matlab and I want to write a generalized condition instead of hard-coding all possible combinations and plotting the outcome. I want to be able to plot up to 6 parameters in one graph with a compact code instead of writing the conditions 6!=6x5x4x3x2x1=720 times :/. To get a feel of my code:
list={‘Live data’,’Historic data’};
[type,tf] = listdlg(‘ListString’,list);
if type==1
list_title={‘a’,’b’,’c’};
[Topic_ID,tf] = listdlg(‘ListString’,list_title);
if 1 >= Topic_ID <= 3
list_var={‘NO2′,’CO’,’SO2′,’H2S’,’humidity’,’temperature’};
[var_pos,tf] = listdlg(‘PromptString’,’Select a variable to plot:’,’ListString’, list_var);
var_size=size(var_pos);
if var_pos==1 %Plot only NO2
figure(1)
t=datenum(datetime,’yyyy-mm-ddTHH:MM:SS.FFF’);
plot(t,NO2)
datetick(‘x’,’dd-mmm-yyyy HH:MM:SS’,’keepticks’,’keeplimits’);
xlabel(‘Time (dd-mmm-yyyy HH:MM:SS)’);
ylabel(‘NO2 (ppb)’);
title(‘NO2’);
legend(‘NO2’);
end
if isequal(var_pos,[1,2]) %Plot CO and NO2
figure(7)
t=datenum(datetime,’yyyy-mm-ddTHH:MM:SS.FFF’);
plot(t,NO2,t,CO)
datetick(‘x’,’dd-mmm-yyyy HH:MM:SS’,’keepticks’,’keeplimits’);
xlabel(‘Time (dd-mmm-yyyy HH:MM:SS)’);
ylabel(‘CO & NO2 (ppb)’);
title(‘CO & NO2’);
legend(‘NO2′,’CO’);
end
Where var_pos is the matrix that contains which list items were chosen. Appreciate any help. I can’t figure it out.I want to find a way to write a compact script that requests user input on a listdlg box and plots a graph depending on the parameters chosen (could be multiple parameters). I am relatively new to matlab and I want to write a generalized condition instead of hard-coding all possible combinations and plotting the outcome. I want to be able to plot up to 6 parameters in one graph with a compact code instead of writing the conditions 6!=6x5x4x3x2x1=720 times :/. To get a feel of my code:
list={‘Live data’,’Historic data’};
[type,tf] = listdlg(‘ListString’,list);
if type==1
list_title={‘a’,’b’,’c’};
[Topic_ID,tf] = listdlg(‘ListString’,list_title);
if 1 >= Topic_ID <= 3
list_var={‘NO2′,’CO’,’SO2′,’H2S’,’humidity’,’temperature’};
[var_pos,tf] = listdlg(‘PromptString’,’Select a variable to plot:’,’ListString’, list_var);
var_size=size(var_pos);
if var_pos==1 %Plot only NO2
figure(1)
t=datenum(datetime,’yyyy-mm-ddTHH:MM:SS.FFF’);
plot(t,NO2)
datetick(‘x’,’dd-mmm-yyyy HH:MM:SS’,’keepticks’,’keeplimits’);
xlabel(‘Time (dd-mmm-yyyy HH:MM:SS)’);
ylabel(‘NO2 (ppb)’);
title(‘NO2’);
legend(‘NO2’);
end
if isequal(var_pos,[1,2]) %Plot CO and NO2
figure(7)
t=datenum(datetime,’yyyy-mm-ddTHH:MM:SS.FFF’);
plot(t,NO2,t,CO)
datetick(‘x’,’dd-mmm-yyyy HH:MM:SS’,’keepticks’,’keeplimits’);
xlabel(‘Time (dd-mmm-yyyy HH:MM:SS)’);
ylabel(‘CO & NO2 (ppb)’);
title(‘CO & NO2’);
legend(‘NO2′,’CO’);
end
Where var_pos is the matrix that contains which list items were chosen. Appreciate any help. I can’t figure it out. I want to find a way to write a compact script that requests user input on a listdlg box and plots a graph depending on the parameters chosen (could be multiple parameters). I am relatively new to matlab and I want to write a generalized condition instead of hard-coding all possible combinations and plotting the outcome. I want to be able to plot up to 6 parameters in one graph with a compact code instead of writing the conditions 6!=6x5x4x3x2x1=720 times :/. To get a feel of my code:
list={‘Live data’,’Historic data’};
[type,tf] = listdlg(‘ListString’,list);
if type==1
list_title={‘a’,’b’,’c’};
[Topic_ID,tf] = listdlg(‘ListString’,list_title);
if 1 >= Topic_ID <= 3
list_var={‘NO2′,’CO’,’SO2′,’H2S’,’humidity’,’temperature’};
[var_pos,tf] = listdlg(‘PromptString’,’Select a variable to plot:’,’ListString’, list_var);
var_size=size(var_pos);
if var_pos==1 %Plot only NO2
figure(1)
t=datenum(datetime,’yyyy-mm-ddTHH:MM:SS.FFF’);
plot(t,NO2)
datetick(‘x’,’dd-mmm-yyyy HH:MM:SS’,’keepticks’,’keeplimits’);
xlabel(‘Time (dd-mmm-yyyy HH:MM:SS)’);
ylabel(‘NO2 (ppb)’);
title(‘NO2’);
legend(‘NO2’);
end
if isequal(var_pos,[1,2]) %Plot CO and NO2
figure(7)
t=datenum(datetime,’yyyy-mm-ddTHH:MM:SS.FFF’);
plot(t,NO2,t,CO)
datetick(‘x’,’dd-mmm-yyyy HH:MM:SS’,’keepticks’,’keeplimits’);
xlabel(‘Time (dd-mmm-yyyy HH:MM:SS)’);
ylabel(‘CO & NO2 (ppb)’);
title(‘CO & NO2’);
legend(‘NO2′,’CO’);
end
Where var_pos is the matrix that contains which list items were chosen. Appreciate any help. I can’t figure it out. listdlg, multiple plots MATLAB Answers — New Questions