How Do You Create a Large Character Array in MATLAB?

  • MATLAB
  • Thread starter Snk_majin
  • Start date
  • Tags
    Array Matlab
In summary, the conversation discusses creating a 100 x 5000 array of characters in matlab. The person asking for help mentions looking into using java strings, but would prefer to learn the core workings of matlab. The response suggests using the "help char" command and using curly brackets to create the array. An example is given and the use of ";" to move data to the next row is explained.
  • #1
Snk_majin
2
0
Hi,

I hope you can help, I'm trying to create an array of characters in matlab:

It has to be 100 x 5000 in size, I'm not to sure where to start. I've looked at some web resources and it some mention bringing in java strings?

I'd ideally not like to use java as i want to learn the core workings of matlab.

Is there a way this can be done? I'd really appreciate any helped offered..

Thanks for your time
Snk_majin
 
Physics news on Phys.org
  • #2
Hello, i hope i can help You.

You can start from inputing "help char" command in You Matlab Command window. You will see several exaples on creating the char array.
 
  • #3
u make it just like a numerical matrix... but instead of using brackets --> [], u use the curly brackets --> {}

ex.

>> x = {'I' 'am' 'using';'a' 'character' 'array'}

x =

'I' 'am' 'using'
'a' 'character' 'array'

>>

get it? just do it with the number of rows and columns you need... btw, the " ; " allows the data to be put onto the next row... refer to the above.. hope that helped...
 

1. What is a char array in Matlab?

A char array, short for character array, is a data type in Matlab used to store sequences of characters or strings. It is a one-dimensional array where each element represents a single character and can be manipulated using various string functions.

2. How do I create a char array in Matlab?

To create a char array in Matlab, you can use the function "char" followed by the string or sequence of characters you want to store. For example, "my_array = char('Hello World')" will create a 1x11 char array with the string "Hello World" stored in it.

3. How can I access and modify elements in a char array in Matlab?

To access elements in a char array, you can use indexing. For example, to access the third element in a char array named "my_array", you would use "my_array(3)". To modify an element, you can simply assign a new value to it using indexing, such as "my_array(3) = 'Z'".

4. Can a char array in Matlab store numbers?

No, a char array in Matlab can only store characters or strings. If you want to store numbers, you can convert them to strings using the "num2str" function before storing them in a char array.

5. How do I convert a char array to a string in Matlab?

You can use the "string" function to convert a char array to a string in Matlab. For example, "my_string = string(my_array)" will convert the char array "my_array" to a string and store it in the variable "my_string".

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
Back
Top