Matlab compatibility? What is wrong? - matlab

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!

Related

Can i suppress Matlab Unit Test Framework's annoying call stack for warnings?

Matlab's UT framework seems to print out a long call stack of internal methods of the framework itself. This results into an annoying flood of completely useless information if your test case causes lots of warnings. Is there a way to suppress the call stack but not the warning itself?
Example code:
classdef fooTest < matlab.unittest.TestCase
methods (Test)
function bar(testCase)
testCase.verifyEqual(0,0);
warning('!!!!!');
end
end
end
Running the test:
>> result = run(fooTest);
Running fooTest
Warning: !!!!!
> In fooTest/bar (line 7)
In matlab.unittest.TestRunner/evaluateMethodCore (line 790)
In matlab.unittest.TestRunner/evaluateMethodsOnTestContent (line 737)
In matlab.unittest.TestRunner/runTestMethod (line 1061)
In matlab.unittest.TestRunner/runTest (line 1015)
In matlab.unittest.TestRunner/repeatTest (line 441)
In matlab.unittest.TestRunner/runSharedTestCase (line 416)
In matlab.unittest.TestRunner/runTestClass (line 943)
In matlab.unittest.TestRunner/invokeTestContentOperatorMethod_ (line 838)
In matlab.unittest.plugins.TestRunnerPlugin/runTestClass (line 407)
In matlab.unittest.plugins.testrunprogress.ConciseProgressPlugin/runTestClass (line 61)
In matlab.unittest.plugins.TestRunnerPlugin/invokeTestContentOperatorMethod_ (line 696)
In matlab.unittest.TestRunner/evaluateMethodOnPlugins (line 696)
In matlab.unittest.TestRunner/runTestSuite (line 880)
In matlab.unittest.TestRunner/invokeTestContentOperatorMethod_ (line 838)
In matlab.unittest.plugins.TestRunnerPlugin/runTestSuite (line 250)
In matlab.unittest.plugins.FailureDiagnosticsPlugin/runTestSuite (line 106)
In matlab.unittest.plugins.TestRunnerPlugin/invokeTestContentOperatorMethod_ (line 696)
In matlab.unittest.plugins.TestRunnerPlugin/runTestSuite (line 250)
In matlab.unittest.plugins.DiagnosticsRecordingPlugin/runTestSuite (line 184)
In matlab.unittest.plugins.TestRunnerPlugin/invokeTestContentOperatorMethod_ (line 696)
In matlab.unittest.plugins.TestRunnerPlugin/runTestSuite (line 250)
In sltest.testmanager.plugins.TestManagerResultsPlugin/runTestSuite (line 60)
In matlab.unittest.plugins.TestRunnerPlugin/invokeTestContentOperatorMethod_ (line 696)
In matlab.unittest.TestRunner/evaluateMethodOnPlugins (line 696)
In matlab.unittest.TestRunner/run (line 288)
In matlab.unittest.TestSuite/run (line 543)
In matlab.unittest.internal.RunnableTestContent/run (line 48)
.
Done fooTest
__________
What version of MATLAB are you using? In more recent versions these stack frames are trimmed such that the framework stacks are not included but the relevant stack frames from the test down into the code being tested is still shown.
Your solution to turn of the stack frames entirely might be a good workaround for earlier versions, but it is a big hammer, and more recent versions should give you less extraneous information while still providing you with the information that is more likely to be useful.
Also, I would certainly encourage you to aim to run your test code without warnings at all. They can certainly be indicative of problems. In fact, you can configure your runner to be more strict and fail in the presence of these warnings to keep your testing clean. To do this use the FailOnWarningsPlugin, or runtests(..., 'Strict',true). In the event that you do indeed have a valid warning you should be able to test against that using the verifyWarning method or IssuesWarnings constraint, which works well with this workflow and does the right thing. Finally, if there is a case where you aren't testing for a warning but for some reason you can't avoid the warning being issued you can leverage the SuppressedWarningsFixture.
Hope that helps,
Andy
I found it:
warning('off','backtrace')

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 newbie: error using sprintf. Function is not defined for 'matlab.graphics.GraphicsPlaceholder' inputs

Today I tried to run a MATLAB m-file that someone gave me. It works fine for him, but I encountered a warning and errors (below). I am using a Mac with OS X Yosemite (10.10.5) and a new version of MATLAB (R2015b). The person who prepared the m-file would have used an older one and Windows.
From a blog at Mathworks and posts online/here, the error seems to be due to a MATLAB update--a change from using numeric values to point towards graphics objects to using objects themselves. I understand this in theory, but don't know how to fix my code (it has been years since I used MATLAB regularly, so I'm pretty lost).
Warning: Text handle output is not supported when a contour handle
argument is supplied and label placement is automatic.
In clabel (line 214)
In control_volume_20150706>plot_xxx (line 733)
In control_volume_20150706 (line 104)
In run (line 96)
Error using sprintf
Function is not defined for
'matlab.graphics.GraphicsPlaceholder' inputs.
Error in control_volume_20150706>plot_xxx (line 734)
sprintf('%10.4f \n',text_handle);
Error in control_volume_20150706 (line 104) plot_xxx (nr,
xwidevec, yhighvec, omegamat, psimat, umat, vmat, ...
Error in run (line 96) evalin('caller', [script ';']);
This is what the code looks like in the vicinity of line 733:
Line 731 contourlevels = omegamat(1, :) ;
Line 732 [C,h] = contour(X,
Y, flipud(omegamat), contourlevels, 'LineWidth', 2 );
Line 733
text_handle = clabel(C,h);
Line 734 sprintf('%10.4f \n',text_handle);
I would be very grateful for any hints about how to deal with this.
If h is a handle which refers to some object, then in R2015a and later this is the object itself, while in previous versions it's a double which points to an object (as you noted in the question). You can use h.double in R2015a and later to get what would previously be h. E.g., pre-R2015a h = figure(999) would set h to 999, a double; with R2015a and later h is an object and h.double is 999.

Data across GUI, 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!

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.