MATLAB Matlab arrays with numbers and characters

AI Thread Summary
Creating an array in Matlab that combines numbers and characters as specified is not possible using standard matrices, as they only support uniform data types. Instead, a cell array can be utilized to achieve the desired output format. For example, a 2x2 cell array can mix doubles and characters, shown as C = {1 'a'; 'b' 21}. This allows for the inclusion of both numeric and character data in a single structure. Refer to Matlab's documentation for comprehensive guidance on using cell arrays effectively.
kaos4
Messages
4
Reaction score
0
So, I'm trying to create an array with both numbers and specific characters, like # and C. I want it to be displayed like a standard array of numbers. So the output would resemble.

7 7 7 7 7 7 7
6 6 6 6 6 6 6
5 # C 6 6 @ 6

Thanks,
 
Physics news on Phys.org
You can't store different data types in the same matrix in Matlab in the manner in which you want. You can, however, use a cell array to do what you want. For instance, to create a 2x2 cell array with a mixture of double and chars one would type

Code:
> C = {1 'a'; 'b' 21}

C = 

    [1]    'a' 
    'b'    [21]

Check Matlab's documentation for *loads* of info on how to use cell arrays.
 

Similar threads

Back
Top