MATLAB Answers

How can I save the total number of each selection from a listdlg using num2str?

4 views (last 30 days)
Jose Rego Terol
Jose Rego Terol on 22 Jan 2020
Edited: Jose Rego Terol on 25 Jan 2020
Hi all,
I want to display how many times each choice of a list has been selected in the xlabel plot.
This is the code for the xlabel:
f1=figure(1);
set(f1,'units','normalized','position',[0 0 1 1],'NumberTitle','on','ToolBar', 'None');
f1.WindowState = 'maximized';
hold on;box on; grid on;
plot(x,y,'b');
ylabel('Amplitud (pA)');
xlabel(['Time (s)' ' foot-Spike: ' num2str(mNum) ' Another event (Flicker): ' num2str(mNum)...
' Spike (Kiss&Run): ' num2str(mNum) ' Null event: ' num2str(mNum) ])
axis([x(1) x(length(x)) min(abs(y)) max(y)]); % Update plot
title('Select two points around a ROI', 'interpreter','none');
ylim([-100 200]);
This is the code for the list:
list = {'Foot Signal of the current spike','Another event (Flicker)',...
'Spike (Kiss&Run)','Null event','Redo de selecction'};
result = listdlg('PromptString',{'So far ' num2str(mNum) ' regions were measured'}, 'SelectionMode','single','ListString',list);
if result==1
mNum = mNum+1;
save([mainDir 'Spike No' num2str(mNum,'%d') '.mat'], 'T','I')
elseif result==2
mNum = mNum+1;
save([mainDir 'Flicker No%d' num2str(mNum,'%d') '.mat'], 'T','I');
elseif result==3
mNum = mNum+1;
save([mainDir 'Spike Kiss&Run' num2str(mNum,'%d') '.mat'], 'T','I');
...
end
When I write, for example, num2str(list{1}), Matlab says Undefined variable list. I tried almost every option but I cannot get the solution.
I guess the problem is that list is a string. Therefore, num2str is not correct, but I am not sure.
Update:
I set the varible list as a global variable
global list
I've change the xlabel code:
xlabel(['Time (s)' ' foot-Spike: ' num2str(list==1)])
And this is the Matlab error:
Undefined operator '==' for input arguments of type 'cell'.
Error in spikes_detection_listdlg (line 34)
xlabel(['Time (s)' ' foot-Spike: ' num2str(list==1)])
May you help me?
Update (25.01.2020):
I found the way to add +1 at each spike type at the xlabel, BUT after the first slection, the counter reset. Therefore, the num2str does not exceed number 1.
global fs
global fl
global KnR
global null
f1=figure(1);
set(f1,'units','normalized','position',[0 0 1 1],'NumberTitle','on','ToolBar', 'None');
f1.WindowState = 'maximized';
hold on;box on; grid on;
plot(x,y,'b');%axis tight;
ylabel('Amplitud (pA)');
xlabel(['Time (s)' 'foot-Spike: ' num2str(fs) ' Flicker:' num2str(fl)])
axis([x(1) x(length(x)) min(abs(y)) max(y)]); % Update plot
list = {'Foot Signal of the current spike','Another event (Flicker)',...
'Spike (Kiss&Run)','Null event','Redo de selecction','Close all'};
result = listdlg('PromptString',{'So far ' num2str(mNum) ' regions were measured'}, 'SelectionMode','single','ListString',list);
fs=result==1;
fl=result==2;
KnR=result==3;
null=result==4;
if result==1
mNum = mNum+1;
fs= fs+1;
save([mainDir 'Spike No' num2str(mNum,'%d') '.mat'], 'T','I')
elseif result==2
mNum = mNum+1;
fl=fl+1;
save([mainDir 'Flicker No%d' num2str(mNum,'%d') '.mat'], 'T','I');
elseif result==3
mNum = mNum+1;
KnR=KnR+1;
save([mainDir 'Spike Kiss&Run' num2str(mNum,'%d') '.mat'], 'T','I');
...
end

  0 Comments

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 23 Jan 2020
xlabel(['Time (s)' ' foot-Spike: ',list{i}])
Here i is any number, not larger than length of list

  2 Comments

Jose Rego Terol
Jose Rego Terol on 23 Jan 2020
Not sure if you understand my problem.
Please, let me reformulate it again.
The list has 5 options: Foot Signal of the current spike, Another event (Flicker), Spike (Kiss&Run), Null event, and Redo de selecction. What I want to do with the code is to count the number of selection of each option and display each value at the xlabel. For example, if the user selects 7 times "Foot Signal of the current spike", I want the code to display the number 7 at the x label where "Foot-spike" is written.
Therefore the codeline you gave me is unnaccurate because {i} is any option of the list. If the user selects the option "Null event", the code should not increase in 1 point the number of Foot-spike for the xlabel linecode. Did you understand the problem better?
Thanks for your time Kalyan.
Jose Rego Terol
Jose Rego Terol on 25 Jan 2020
I change the code:
global fs
global fl
xlabel(['Time (s)' 'foot-Spike: ' num2str(fs) ' Flicker:' num2str(fl)])
list = {'Foot Signal of the current spike','Another event (Flicker)',...
'Spike (Kiss&Run)','Null event','Redo de selecction','Close all'};
result = listdlg('PromptString',{'So far ' num2str(mNum) ' regions were measured'}, 'SelectionMode','single','ListString',list);
fs=result==1;
fl=result==2;
if result==1
mNum = mNum+1;
fs= fs+1;
save([mainDir 'Spike No' num2str(mNum,'%d') '.mat'], 'T','I')
elseif result==2
mNum = mNum+1;
fl=fl+1;
save([mainDir 'Flicker No%d' num2str(mNum,'%d') '.mat'], 'T','I');
Now the flicker selection is counted in the xlabel Flicker, BUT the counter is rest every time I select a new spike. In other words, the code does not save the number of selections.
How can I save all the number of selections?

Sign in to comment.

Sign in to answer this question.

Tags