Thread Subject: Horzcat errors

Subject: Horzcat errors

From: Abner

Date: 17 Jul, 2009 14:40:20

Message: 1 of 7

Hi all,
I have made a fis file and tried to link it to my m file. When doing so, I get the error below,

??? Error using ==> horzcat
The following error occurred converting from double to struct:
Error using ==> struct
Conversion to struct from double is not possible.

what is wrong actually?
Thanks.

Subject: Horzcat errors

From: Matt

Date: 17 Jul, 2009 15:13:01

Message: 2 of 7


You are attempting an undefined conversion (from struct to double).

Subject: Horzcat errors

From: Chris Johnson

Date: 17 Jul, 2009 15:17:03

Message: 3 of 7

The chance is that somewhere in your code you need to include a conversion. It basically involves a little bit of inventive codeing. Debug your m-file using breakpoints and examine the data it is trying to convert then use help to find out how to convert the data correctley. For example struct() can be used to convert data into a structured array.

S = struct('A', {5, 'Anne', @myfun, 1:5});


Without information about what exactley your doing this is the best I can do. But I expect that you trying to concatenate two matricies with different formats.

I had a similar problem and this is the code that solved the problem for me. The file I load in is read in as a structured array and I wanted to add to it a string of the filename. To do this I converted each string to a cell before adding it to an array and once finished converted the remaing structered array to a cell array before joining the two arrays together as they were now both cell arrays.

dat_l = [];
dat_r = [];
for i = startnum:endnum
    filename2 = [num2str(i),'.mat'];
    load(filename2)
    dat_l = cat(1,dat_l,[i, num_edges, num_def.left, num_def.right]);
    filename2 = cellstr(filename2);
    dat_r = cat(1,dat_r,filename2);
    
end
dat_l = num2cell(dat_l);
global dat;
dat = cat(2,dat_l,dat_r);

 set(handles.uitable1, 'Data',dat);

I hope this helps
Chris

Subject: Horzcat errors

From: Samuel Dorrell

Date: 17 Jul, 2009 15:42:01

Message: 4 of 7

"Chris Johnson" <donotuse@hotmail.com> wrote in message <h3q4lf$k3a$1@fred.mathworks.com>...
> The chance is that somewhere in your code you need to include a conversion. It basically involves a little bit of inventive codeing. Debug your m-file using breakpoints and examine the data it is trying to convert then use help to find out how to convert the data correctley. For example struct() can be used to convert data into a structured array.
>
> S = struct('A', {5, 'Anne', @myfun, 1:5});
>
>
> Without information about what exactley your doing this is the best I can do. But I expect that you trying to concatenate two matricies with different formats.
>
> I had a similar problem and this is the code that solved the problem for me. The file I load in is read in as a structured array and I wanted to add to it a string of the filename. To do this I converted each string to a cell before adding it to an array and once finished converted the remaing structered array to a cell array before joining the two arrays together as they were now both cell arrays.
>
> dat_l = [];
> dat_r = [];
> for i = startnum:endnum
> filename2 = [num2str(i),'.mat'];
> load(filename2)
> dat_l = cat(1,dat_l,[i, num_edges, num_def.left, num_def.right]);
> filename2 = cellstr(filename2);
> dat_r = cat(1,dat_r,filename2);
>
> end
> dat_l = num2cell(dat_l);
> global dat;
> dat = cat(2,dat_l,dat_r);
>
> set(handles.uitable1, 'Data',dat);
>
> I hope this helps
> Chris

I'm not sure what a fis file is but I've had a similar error before while using data structures in Simulink (error: expecting a uint16, found a double, or something to that effect). The problem wasn't anything to do with data types it was to do with data dimensions and I spent quite a while trying find out how my uint16 had unwittingly been converted. So just a word of warning, if Chriss's suggestion doesn't work then perhaps the error lies elsewhere!

Subject: Horzcat errors

From: Abner

Date: 18 Jul, 2009 16:41:01

Message: 5 of 7

This is the code im working on which gives the mentioned error. How do I convert double to structure? I think the problem arises when graycomatrix is applied...

I = imread('test.jpg');
J = Locked_cropping(I);
figure,imshow(J),title('Cropped Image');
K = rgb2gray(J);
ent = entropy(K)
GLCM2 = graycomatrix(K);
cont = graycoprops(GLCM2,'contrast')
corr = graycoprops(GLCM2,'correlation')
ener = graycoprops(GLCM2,'energy')
homo = graycoprops(GLCM2,'homogeneity')


%load FIS
FuzzL = readfis('withoutAdapthisteq');

%define FIS input variables

a = ent; % for Entropy
b = cont; % for Contrast
c = corr; % for Correlation
d = ener; % for Energy
e = homo; % for Homogeneity

% Define output variable and enter input variables
res = evalfis([a b c d e], FuzzL)

Subject: Horzcat errors

From: ImageAnalyst

Date: 18 Jul, 2009 18:23:19

Message: 6 of 7

Abner:
graycoprops() returns a structure. You need to do this:

% Get the structures.
strContrast = graycoprops(GLCM2,'contrast')
strCorr = graycoprops(GLCM2,'correlation')
strEnergy = graycoprops(GLCM2,'energy')
strHomo = graycoprops(GLCM2,'homogeneity')

% Extract the structure field into a double.
cont = strContrast.Contrast
corr = strCorr.Correlation
ener = strEnergy.Energy
homo = strHomo.Homogeneity

Good luck,
ImageAnalyst

Subject: Horzcat errors

From: Abner

Date: 19 Jul, 2009 08:01:04

Message: 7 of 7

 ImageAnalyst: Thank you so mch it works fr me now! You're a life-saver! All the best ;)

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
struct Sprinceana 22 Aug, 2009 06:23:15
horrizontal con... Sprinceana 22 Aug, 2009 06:22:58
horzcat Sprinceana 18 Jul, 2009 13:39:58
rssFeed for this Thread

Contact us at files@mathworks.com