MATLAB: Adding 2 string row to beginning row and end row of a matrix

matrixstringstrings

Hello, I'm a beginner for MATLAB, and I need your helps to solve my problem.
I have a numeric matrix, and it's written to excel in 'for loop' for distinct period. and I want to add some strings to the beginning row and end row of this numeric matrix. You can see like this:
A = [x, y, z] ;
hold on
A = [123, 0 , 0 ;
A;
987, 0 , 0] ;
For above code, it's running correctly, but I need some strings instead of "123" and "987" and zeros. For example; I just want to replace "123 " with "Hello", and to replace "987 " with "Bye", and to replace "0" (all zeros) with empty arrays(nothing) in order to write to excel file. How can I do this? Thanks in advance!

Best Answer

A numeric data type cannot hold text. You'll need to store your data in a variable that can hold mixed types. One possibility is a cell array. Here is one way to do it:
A = [1, 2, 3];
cellA = num2cell(A);
cellA = [{'yes', 'no', 'maybe'};
cellA;
{'yes', 'no', 'maybe'}];
Cell arrays can be a bit tricky to use at first, especially because you need to be careful about using curly brackets instead of square brackets.