Object is Invalid or Deleted when pressing button and plotting - matlab

Please help. The error says that the object is deleted.
Error using handle.handle/get
Invalid or deleted object.
Error in C:\Program Files\MATLAB\R2011b\toolbox\matlab\graph2d\plotyy.p>localUpdatePosition (line 373)
Error in C:\Program Files\MATLAB\R2011b\toolbox\matlab\graph2d\plotyy.p>#(obj,evd (localUpdatePosition(obj,evd,ax(1),ax(2))) (line 212)
I really do not understand what was deleted but every time I perform the impz(signal), the plot isn't showing the correct graph unlike the plot in freqz(signal) and zplane(signal).
This is what really happens (26seconds video) - https://www.youtube.com/watch?v=HTR45lNIjuc
Line 212 contains this code handles.N = str2num(get(handles.edtOrder,'String'));
Line 373 contains this code zplane(handles.axPlots,handles.firVector,1)
Code for impulse response
if (get(handles.cbImpResp,'Value') == 1)
set(handles.txtPlotAvail,'Visible','off');
switch (handles.filterValue)
case 'FIR'
impz(handles.axPlots,handles.firVector,1)
case 'IIR'
impz(handles.axPlots,handles.vectorB,handles.vectorA)
case 'Multiple Bandpass'
end
else
set(handles.txtPlotAvail,'Visible','on');
end

The code is either mixing up your handles or overwriting old ones. There no way to debug this without the full source.
See http://www.mathworks.com/matlabcentral/answers/85117

Related

Sensoray 826 cards driver problems with MATLAB

this is my first topic if anything wrong please advise me.
I am not a great matlab user but I need to use matlab with sensoray 826 to capture the data.
However, once I install the driver and try to run 826 Matlab demo I got the error code below.
Warning: Warnings messages were produced while parsing. Check the functions you intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
I try to find the root cause of this problem and get new error.
[notfound, warnings] = loadlibrary('C:\Program Files (x86)\Sensoray\826\API\x64\s826.dll')
Error using loadlibrary
There was an error loading the library "C:\Program Files (x86)\Sensoray\826\API\x64\s826.dll"
Unrecognized function or variable 's826_proto'.
Caused by:
Error using feval
Unrecognized function or variable 's826_proto'.
At this point I believe that the error is cause from incorrect DLL file from the sensoray.
I try to contact the Sensoray but they rarely answer back to me.
If anyone know how to solve this issue please kindly reply back to me.
The code I use to run in Matlab:
% Load the 826 API and open a connection to the 826 board
dllPath = 'C:\Program Files (x86)\Sensoray\826\API\x64\s826.dll'; % Replace with the correct path to the DLL file
hdrPath = 'C:\Program Files (x86)\Sensoray\826\API\826api.h'; % Replace with the correct path to the header file
[errcode, boardflags] = s826.SystemOpen(dllPath, hdrPath);
if errcode ~= 0
error('Error opening connection to 826 board: %d', errcode);
end
% Configure the rotary sensor
counter = 0; % Choose the counter that the rotary sensor is connected to (0-3)
s826.CounterModeWrite(counter, s826.CNTR_QUADX4); % Configure the counter for quadrature input
s826.CounterPreloadWrite(counter, 0, 0); % Reset the counter
% Read the counter value
count = s826.CounterRead(counter);
% Close the connection to the 826 board
s826.SystemClose();
I would like to go step by step since I never use this 826 cards before.
So first just correctly call the DLL and H file is enough for me.

Adding a debug point as soon as an error appears MATLAB

this might be silly, Is there any way to automatically place a debug point when an error pops up in MATLAB
Error popping is done manually by
msg = 'Error has occurred'
error(msg)
What I need is, to automatically put a debug (not by manual intervention) after popping this error.
You can use dbstop with a condition:
dbstop if error
MATLAB pauses at any line in any file when the specified condition
occurs.

Store returned errors (or messages) of MATLAB as cell array

Suppose that running m-file in MATLAB R2015a returns 5 errors. I want store these errors (or messages) separately in a cell array. for example c{1} is first error, c{2} is second error, etc. I can't use try-catch structure because m-files are nested (I didn't create these m-files) and i can't find origin of an error. I want only return error(s) in my created GUI dialogs based on these m-files.
Sample error:
Error using i_a (line 102)
IDETooManyParams
Error in i_a (line 280)
[idehess_point, idemoments_point, idemodel_point, idelre_point, derivatives_info_point,
info] = ...
Error in ex5 (line 188)
i_a(options_ident);
Error in xx(line 180)
evalin('base',fname) ;
I want have IDETooManyParams as a string (or possibly other errors).
You can get the last error message and the stacktrace through lasterror.

How to deal with expired URL links when using imread URL?

I am working on the face scrub dataset, which has a long list of urls of pictures.
I used a for loop to fetch these photos. However, some of the urls had expired so my matlab code return an error saying 'Unable to determine the file format.' However I think the actual reason is that the url link does not have the image anymore. For example, one of the bad urls is:
http://www.gossip.is/administrator/components/com_n-myndir/uploads/16de47418d69b1c2991731dffaca8a78.jpg
How do I identify and ignore this error so my code can keep working on the rest of the list? I could use R instead if that make solving this problem easier.
You can implement a try/catch block to catch (original isnt'it) the error message and skip the image if the link is indeed broken.
When we use the following syntax:
try
A = imread('http://www.gossip.is/cgi-sys/suspendedpage.cgi');
catch ME
%// Just so we know what the identifier is.
ME
end
Matlab first tries to read the image given by the url. If it can't, we ask it to catch the error message (MException actually) and perform some other appropriate action.
The thing is, we need to know what is the exact error message in order to recognize it in the try/catch block.
When I entered the above code, I got the following structure for ME:
ME =
MException with properties:
identifier: 'MATLAB:imagesci:imread:fileFormat'
message: 'Unable to determine the file format.'
cause: {0x1 cell}
stack: [2x1 struct]
Therefore, once we know the exact identifier generating the error we can use strcmp to look for it in the try/catch block. For instance with the following code:
clear
clc
try
A = imread('http://www.gossip.is/cgi-sys/suspendedpage.cgi');
catch ME
if strcmp(ME.identifier,'MATLAB:imagesci:imread:fileFormat')
disp('Image link broken')
end
A = imread('peppers.png');
end
imshow(A);
Matlab displays 'Image link broken' and reads peppers.png, as expected.
Hope that helps!

Matlab exception sent by mail is not showing the line of the error

In my matlab script I am sending a mail to me with an exception that tells me, when an error happens, which kind of error it is.
The problem I am facing is the fact that the ME exception is not showing me where the error happens (which line and which part of the code) as matlab usually does. I can't see the error in the matlab terminal too (the program just stops running). The code that sends the mail with the error is below:
try
% my script which can fail....
demo
catch ME
% An error will put here.
errorMessage = sprintf('Error in demo. The error is: %s', ME.message);
%this function just sends the mail
sendmail2me(errorMessage);
What I missed?
The exception ME is an MException object which contains an identifier, the message, a cause and the stack. The identifier is only there to allow MATLAB an unique identification of an error. The message contains a description of the error.
The cause contains an array of MExceptions which have led to the current exception. This allows you to track the exceptions to find the root of your error. As the cause is a (possibly empty) array of MException objects, you could go through the cause in an array and write the information into the mail.
Most important for you is the stack. It is a struct containing three fields: file, name and line. File is the full path to the file/function where the error occurred. Name is (obviously) the name of the file and in line (again obviously) the line where the exception occurred is saved. The stack can also be an array if the error occurred in a function called from you function/script. It would therefore be best to go through stack in a for loop, and concatenate the error message and the contents of the stack.
try
demo;
catch ME
errormsg = sprintf('%s\n',ME.message);
for k=1:length(ME.stack)
errormsg = sprintf('%s\nError in %s (line %d)\n', ...
errormsg,ME.stack(k).name,ME.stack(k).line);
end
sendmail2me(errormsg);
end
You find more detailed information on Exceptions in the MATLAB help pages.