Need help with something that im trying to do with Listbox.
1 view (last 30 days)
Show older comments
I have seen examples of listbox that show how they open pics and files, but i want to show a graph(In this case a sawtooth wave). After some maths for the fourier series this is what i have and it works in the editor:
clear,clc;
t=(0:0.01:10);
n=input('número de harmónicas: ');
Vo=0.5;
Wo=2;
Vn=Vo*ones(1,length(t));
for k=1:1:n
Vn=Vn-1/k/pi*sin(k*Wo*t);
end
plot(t,Vn)
When you run this, you introduce a number and will show you a graph. For the GUI part, i put a listbox with some numbers (10,20,30) as "n". What i want to do is that when i select the number, the graph of the series shows in the axes. I dont know where should i put my "cycle for", i tried using switch-case in the listbox but im not sure what is the opening function. How can i made my gui work for this case?? If there's another way? but my teacher want the listbox for the "n" values. I hope you understand, english is not my main language. Thanks in advance.
0 Comments
Accepted Answer
Image Analyst
on 2 Dec 2013
Something like this to fill up the listbox:
listboxContents = {'10', '20', '30'};
set(handles.listbox1, 'String', listboxContents);
Or just pre-fill it in GUIDE. Then get the selected item
listboxContents = get(handles.listbox1, 'String');
selectedItem = get(handles.listbox1, 'Value');
selectedString = listboxContents{selectedItem};
selectedNumber = str2double(selectedString);
Then do whatever you want to do with the item that was selcted.
More Answers (0)
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!