Hi all,
im coding a fairly easy app with app designer and im struggling with the input/output for List Box property "ItemsData".
What i want to do is to show the user 2 options ("Items") in a list-box. These options then lead to vectors of 2 numbers ("ItemsData"). Lets say:
With ItemsData(Option 1) = [2950 3350] and ItemsData(Option 2) = [3600 4500]
Now i want to use these 2 integers in my main function and i cant figure out how to do the indexing right. I tried using a cell array as ItemsData with combined indexing:
A = B{1,1}(1,1)
which leeds to an error because of the curly brackets.
If it is any easier with a Switch or DropDown its fine too! There are just 2 options.
Thanks for any help on this!

 채택된 답변

Oskar Kilgus
Oskar Kilgus 2022년 8월 21일

0 개 추천

I found a way to do it (If anyone is having trouble with this issue in the future)
1) List-Box ItemsData as 1x2 numeric vector:
[1 2]
2) value-changed function callback:
% Value changed function: choosefromListBox
function choosefromListBoxValueChanged(app, event)
app.whatever = str2num(app.choosefromListBox.Value)
end
3) reference in other function:
app.whatever(1,1) %returns 1
______________________________
Thanks @Simon Chan for your effort!

추가 답변 (1개)

Simon Chan
Simon Chan 2022년 8월 21일

0 개 추천

Suppose the listbox is defined as follows and ItemsData are given in your example.
app.ListBox = uilistbox(app.UIFigure);
You may get the data directly via the following:
A = app.ListBox.Value

댓글 수: 8

Thanks for the reply Simon!
In that case A would be a 1x2-numeric vector like [2950 3350] or [3600 4500] right?
The problem is to now refer to eg. the value 2950 in another function in the app.
Can you help me with this?
Try this:
A = app.ListBox.Value(1)
it then says "'Value' must be a double scalar within the range of 'Limits'."
Simon Chan
Simon Chan 2022년 8월 21일
I think you use the value 2950 in another function which requires a lower and upper limit as well.
So you need to define the limits before you use this value on another function. Or the limits you already defined does not cover the value '2950' and hence it gives the above mentioned error.
Could you please let me know the function you are going to use the value '2950'?
Oskar Kilgus
Oskar Kilgus 2022년 8월 21일
편집: Oskar Kilgus 2022년 8월 21일
% Button pushed function: StartButton
function StartButtonPushed(app, event)
fs = 48000;
adr = audioDeviceReader(fs);
buff = dsp.AsyncBuffer(Capacity = fs*3);
numIterations = floor(450*fs/adr.SamplesPerFrame);
o=1;
for index=1:numIterations
frame = adr();
write(buff,frame);
if buff.NumUnreadSamples >= 2*fs
o=o+1;
data = read(buff);
[psp, f] = pspectrum(data,fs);
f_index = find(f >= app.choosefromListBox.Value(1) & f <= app.choosefromListBox.Value(2));
p = 10*log10(psp(f_index));
m(o,:) = mean(p)
end
end
end
f_index is supposed to find f values above the first vector entry (eg. 2950) and below the second entry (eg.3350). So this is where i want to refer to the listbox itemsdata.
oh and this is the value changed function (so u get the syntax):
% Value changed function: choosefromListBox
function choosefromListBoxValueChanged(app, event)
app.FreqRange = app.choosefromListBox.Value
end
Could you please check whether the following lines gives the correct values to you or not?
app.choosefromListBox.Value(1) % gives 2950 to another function
app.choosefromListBox.Value(2) % gives 3350 to another function
Oskar Kilgus
Oskar Kilgus 2022년 8월 21일
편집: Oskar Kilgus 2022년 8월 21일
I tried exactly that (see the code i supplied) and it resulted in the error
"'Value' must be a double scalar within the range of 'Limits'."
The interesting value at the end of the function is m(o,:) = mean(p). I tried it again and now i end up with m=[0; NaN]. For the next iteration i still end up with the error message above!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2022년 8월 20일

답변:

2022년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by