Search code examples
arraysmatlabcellcell-array

How to copy cell to array in Matlab


Alright let me explain detailed my question

this below image is displaying my matrix where i want to copy my data

enter image description here

Alright now what i want to do that is as you can see 1x4 cell i want to copy it as an array to another variable such as

    input_values=ones(1,4);%init
    input_values=input_matrix_training(1);

So at the above i am trying to copy the elements in that cell array which is row 1 to the input_values array. But if i do as i above i am getting this instead of the values that array contains. ty

enter image description here

instead of above it should be like

enter image description here


Solution

  • The other values are a cell, and are thus best referenced with {} instead of (). Also, sometimes they need to be wrapped into [], depending on the format. Plus the fact that you don't need to initialize input_values, and what you should do becomes this:

    input_values=[input_matrix_training{1}];
    

    Or you can just use cell2mat

    input_values=cell2mat(input_values(1));