MATLAB Answers


conversion from double to struct

Asked by God'sSon
on 16 May 2011


i am trying to import (x) which is an audio signal and then concatenate with some zeros but get the following error message. can anyone please help.


x = uiimport('test_signal.mat')

input_signal=x; B = zeros([1,8]); total_input_signal= [B input_signal];

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

Error in ==> output at 10 total_input_signal= [B input_signal];



No products are associated with this question.

2 Answers

Answer by Andrei Bobrov
on 16 May 2011
 Accepted answer

if the mat - file contains one variable

x = uiimport('test_signal.mat');
names =fieldnames(x);
xx = x.(names{:});
total_input_signal = [zeros(1,size(xx,2));xx];

  1 Comment

on 16 May 2011


Answer by Ivan van der Kroon on 16 May 2011

if it is a real sound file like

x = 
     y: [73113x1 double]
    Fs: 8192

you will have a structure as well. For any set of variables you save and load again, the variables will be behind a structure. To perform array/matrix operations on the sound data in this case, you can think of

total_input_signal=[B ; x.y];

If it is still not clear to you, can you specify what variables youre file test_signal.mat is made up by?

  1 Comment

on 16 May 2011


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!