Adding 2 string row to beginning row and end row of a matrix
11 views (last 30 days)
Show older comments
Onur Salih Gumus
on 4 Mar 2021
Edited: Onur Salih Gumus
on 4 Mar 2021
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!
0 Comments
Accepted Answer
the cyclist
on 4 Mar 2021
Edited: the cyclist
on 4 Mar 2021
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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!