Error using get ......Invalid handle???!!!!!

조회 수: 2 (최근 30일)
Nour Mawla
Nour Mawla 2015년 5월 10일
댓글: Adam 2015년 5월 11일
Good after noon everyone
I'm trying to build a GUI that would match an input image and a database of images...I'm using the edge function
but when calling the database I get the following error
Error using get
Invalid handle
That's the function of the button that calls the database
function source_Callback(hObject, eventdata, handles)
load Letters
global Letters;
num=size(Letters,2);
q = zeros (1:num);
for n=1:num
handles.Y=Letters{1,n};
q(n) = get(handles.Y,'n');
guidata(hObject,handles);
end
handles.output = hObject;
Thats the comparing function
load Letters
global Letters;
num=size(Letters,2);
matched = 0;
k = handles.XX;
k = rgb2gray(k);
edge_k= edge(k,'prewitt',[]);
display('testing');
for n=1:num
p = handles.Y;
edge_p = edge(p,'prewitt',[]);
for i = 1:1:400
for j = 1:1:400
if(edge_p(i,j))==1&&(edge_k(i,j)==1)
matched = matched+1;
disp (matched);
end
end
end
and finally the function used in creating the database
clear all;
close all;
clc;
for i = 1:50
A = imread(strcat('Sample 2\A\a',int2str(i),'.png'));
A = rgb2gray(A);
letter=A ;
Letters(1,i)=mat2cell(letter,2048,[1536 ] );
end
save ('Letters','Letters')
Please help me correct the error
when I removed the get function when matching it displayed the same number of matched point for all 50 images
Thank you

답변 (2개)

Image Analyst
Image Analyst 2015년 5월 10일
Never use "clear all;" inside a callback function. It will blow away your handles structure so that you can no longer access it.
  댓글 수: 12
Nour Mawla
Nour Mawla 2015년 5월 11일
and i need values to be in this format (that is the gray scale matrix of each image)
Image Analyst
Image Analyst 2015년 5월 11일
I'm about to give up here. You keep changing your code and don't even attach it like I requested. First you say:
Letters(1,i)=mat2cell(
then you say
Values=mat2cell(
And did you know letters and Letters are different because MATLAB is case sensitive ? Anyway, these are the two links that you need to solve all your MATLAB problems:
and
Good luck.

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


Walter Roberson
Walter Roberson 2015년 5월 10일
Your call
Letters(1,i)=mat2cell(letter,2048,[1536 ] );
is going to be the same as
Letters{i} = letter;
The mat2cell() only has the effect of breaking up the matrix into smaller pieces if the following arguments include at least one non-scalar vector. When both of the values are scalar, the effect would be to give an error message if the array was not 2048 x 1536, and then to wrap the matrix inside a cell array.
Notice that what you store into Letters{i} is not an object, just a numeric matrix. As it is not an object at all, it has no property 'n' to be fetched by get().
I suspect that what you are looking for is something like,
Letters(1,i) = struct('letter', letter, 'n', n );
and then in your callback,
handles.Y = Letters(n).letter;
q(n) = letters(n).n;
  댓글 수: 11
Walter Roberson
Walter Roberson 2015년 5월 11일
Value(i) = mat2cell(letter,2048,[1536 1536]);
Adam
Adam 2015년 5월 11일
Yeah, I couldn't remember which it needed to be and didn't have time to remember how to use mat2cell to test it so I went for the wrong one!

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by