Data across GUI, Matlab - matlab

So i tried to share GUI data using setappdata and getappadata. for example lets consider this
matfile1.m
h = EmotivEEG;
h.Run
for k = 1:4
out(:,:,k) = h.data + rand(1);
setappdata(0,'eegData', out(:,:,k);
pause(0.5);
end
h.delete
so the above file creates a 128x14 matrix every o.5 seconds and store it in eegData
matfile2.m
some_var = getappdata(0,'eegData')
plot(some_var)
this seems to work but not while in the loop, if i ask it to plot it i get this error
Error using setappdata
Too many output arguments.
Error in eeg_live>eeg_live_OpeningFcn (line 83)
lmno = setappdata(0,'eegData');
Error in gui_mainfcn (line 221)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in eeg_live (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in Neucube>activation_Callback (line 3963)
eeg_live
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Neucube (line 49)
gui_mainfcn(gui_State, varargin{:});
Error in #(hObject,eventdata)Neucube('activation_Callback',hObject,eventdata,guidata(hObject))
Error using pause
Error while evaluating uicontrol Callback
any idea on how to tackle this problem.
thanks in advance.

There seems to be some problems with your code, but the line that MATLAB tells you generates the error is not in the snippet you provided, and the message is quite clear:
Using this command (line 83):
lmno = setappdata(0,'eegData');
is forbidden because setappdata does NOT accept output arguments, therefore the error is thrown. You can only use an assignment with getappdata.
Other points to consider:
1) Make sure you use the same variable name with get/setappdata (i.e. either eegdata or eegData...it might be a typo though)
2) You don't seem to call the 2nd script in your loop, so setappdata is overwriting the value of eegData at every iteration.
Hope that helps!

Related

what is the correct inputs for cv.basicfacerecognizer

I am trying to provided sample code for cv.facerecognition in mexopencv - Matlab, but i am getting an error in cv.facerecognition which says
Undefined function or variable 'BasicFaceRecognizer_'.
Error in cv.BasicFaceRecognizer (line 131)
this.id = BasicFaceRecognizer_(0, 'new', ftype, varargin{:});
I couldn't find any solution for that, i appreciate your support
thanks

How to use script in MATLAB allowing functions to be declared?

While making GUI I've came into this problem:
Using script (S) in function (A) makes other functions (B,C,D..., which are declared in function (A)) as undeclared while executing script (S), it happens on MATLAB version R2016b, however everything works fine in MATLAB R2015b.
Basically I have a bunch of axes, and axesPushScript.m script, which executes on click.
Inside script i got this line:
autorange_Callback(handles.autorange, eventdata, handles);
Inside my main function I've got this:
function autorange_Callback(hObject, eventdata, handles)
if (hObject.Value==1)
axis(handles.axesSpectra, 'tight');
axesSpectra_ButtonDownFcn(handles.axesSpectra,eventdata,handles);
else axis(handles.axesSpectra, 'manual');
end
get this error message on MATLAB R2016b:
Undefined function or variable 'autorange_Callback'.
Error in axesPushScript (line 44)
autorange_Callback(handles.autorange, eventdata, handles);
Error in SNOM_alpha_4>axesTrace_ButtonDownFcn (line 463)
axesPushScript;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in SNOM_alpha_4 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>#(hObject,eventdata)SNOM_alpha_4('axesTrace_ButtonDownFcn',hObject,eventdata,guidata(hObject))
Error while evaluating Axes ButtonDownFcn
Any ideas of how I could fix it?
%---------------------------------------------------------------
EDIT:
adding .rar file with a simple one button example:
https://www.dropbox.com/s/gsgxb9xt1s6hbvp/junk.rar?dl=0

TMG matlab tool error

I am trying to generate a tf-idf representation of a text file using TMG matlab tool.
This is how I set up my variables:
When I press continue, I get the following error.
Undefined function or variable 'new_sprintf'.
Error in tmg_p
Error in tmg (line 124)
if nargout==8, [varargout{1}, varargout{2}, varargout{3}, varargout{4}, varargout{5}, varargout{6}, varargout{7},
varargout{8}]=tmg_p(varargin{1}, varargin{2}); end
Error in tmg_gui>ContinueButton_Callback (line 456)
[A, dictionary, global_weights, normalization_factors, words_per_doc, titles, files, update_struct]=tmg(filename, OPT);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in tmg_gui (line 27)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>#(hObject,eventdata)tmg_gui('ContinueButton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
And the environment path changes to: log_files
What's causing this and how can I fix it?
I had this problem too: you have to add the path of TMG to MATLAB before using it.
I had this problem, but installing MATLAB 2013a or 2012b and using an earlier verion of tmg solved my problem.

Matlab compatibility? What is wrong?

I'm using a Matlab code for data analysis (fitting of scattering data), which is written in 2006. This code works with Matlab 2007 well, but at least it doesn't work in Matlab 2009 and newer versions. Therefore I think it is caused by some changes in the runtime environment concerning how to act with GUIs.
In following I post the error message I always get:
Illegal right hand side in assignment. Too many elements.
Error in Frontend>do_fit (line 749)
[handles.fitfunctions{fitfunction_index}.param_vector,
handles.data_fit, exitflag, output] = ...
Error in Frontend>fit_button_Callback (line 673)
do_fit(hObject, handles);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Frontend (line 42)
gui_mainfcn(gui_State, varargin{:});
Error while evaluating uicontrol Callback
Lines 747 to 750 in my function "do_fit" in frontend.m look like:
fitmethods = Fit();
fitmethod = fitmethods{2}.func;
[handles.fitfunctions{fitfunction_index}.param_vector, handles.data_fit,
exitflag, output] = ...fitmethod((#(A,z)fitfunction(const,A,z)), fitparams, xdata,
ydata, lb_vector, ub_vector, weightdata ,options);
I would be very thankful, if someone has an idea what is wrong in this piece of code!

Error in matlab, while using set in GUI

I have tried the following code in Matlab:
function pushbutton5_Callback(hObject, eventdata, handles)
global smoothening_level;
global Amp_threshold;
global Min_PeakDistance;
global Mat_wave
global Mat_wave2
global Mat_inten
global pks
Mat_inten2 = smooth(Mat_inten,smoothening_level);
[pks,locs] = findpeaks(Mat_inten2,'minpeakdistance',Min_PeakDistance,'minpeakheight',Amp_threshold)
s = size(pks)
figure(1)
Mat_wave2 = Mat_wave(locs(:));
Mat_inten2loc = Mat_inten(locs(:));
hold all;
plot(Mat_wave,Mat_inten2);
plot(Mat_wave2,pks,'o','MarkerEdgeColor','r');
legend('Ouptut Spectrum','Smoothened Spectrum','Identified Peaks')
axis([350 900 0 max(Mat_inten)]);
xlabel('Wavelength')
ylabel('Intensity')
grid on
title('Plasma Emission Spectrum')
temp(:,1)=Mat_wave2;
temp(:,2)=Mat_inten2loc;
set(handles.uitable8,'Data',num2cell(temp))
However it is giving the following error:
??? Attempt to reference field of non-structure array.
Error in ==> GUI>pushbutton5_Callback at 242
set(handles.uitable8,'Data',num2cell(temp))
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI at 50
gui_mainfcn(gui_State, varargin{:});
Error in ==> #(hObject,eventdata)GUI('pushbutton5_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
The error tells you that handles is not of type struct. Hence, you can not access handles.uitables8. Most likely what you want to write is
set(handles,'Data',num2cell(temp))', but that is just a guess without knowing the rest of your code.
Check to make sure that handles.uitable8 exists. The easiest way to do this is to set a breakpoint in your code at line 242. When the code stops in debugger, go to your workspace and open the handles structure.
If you created this gui using GUIDE, then most likely the tag is mislabeled or something similar.