Borrar filtros
Borrar filtros

I want to plot different graphs by importing excel file and using checkbox. By using below code i am able to import excel file and it plot graphs by pushbutt but i have big excel file and i want to get specific plot by using checkbox button. Pls help

1 visualización (últimos 30 días)
if true
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
startingFolder = 'C:\Program Files\MATLAB'; % Whatever you want. Could be pwd if you want.
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.xls*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
[numbers, strings, raw] = xlsread(fullFileName);
% Extract x and y
a = numbers(:, 1); % For example, x is in column 1
b = numbers(:, 2);
c = numbers(:, 3);
d = numbers(:, 4);
g = numbers(:, 5);
h = numbers(:, 6);
figure();
plot(a, b, 'b-', 'LineWidth', 2);
grid on;
%%text(a,b,strValues,'VerticalAlignment','bottom');
figure();
plot(a, c, 'r-', 'LineWidth', 2);
grid on;
figure();
plot(a, d, 'y-', 'LineWidth', 2);
grid on;
figure();
plot(a, g, 'g-', 'LineWidth', 2);
grid on;
figure();
plot(a, h, 'v-', 'LineWidth', 2);
grid on;
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
checkboxStatus = get(handles.torque_check,'Value');
end

Respuestas (1)

Walter Roberson
Walter Roberson el 28 de Dic. de 2015
Your code that is in your pushbutton1_Callback can be moved to your checkbox1_Callback. Your checkboxStatus will generally come out as 0 when the box is not checked and as 1 when the box is checked.
If you have multiple checkboxes you should probably consider using a uibuttongroup if you only want one to be active at a time.
Keep in mind though that a difference between a checkbox and a pushbutton is that a pushbutton can be re-triggered: you can plot the same thing multiple times in a row by pushing the button again, but if you want the checkbox to trigger the plotting then to plot the same thing again you would need to uncheck it and then recheck it, which is not good user interface. checkbox should be used for setting choices with some other mechanism for initiating the action (such as a pushbutton.)

Categorías

Más información sobre 2-D and 3-D Plots 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!

Translated by