1

I simply want to get the string out of the cell. Every time I try to make string operations it stores the variable into a cell. I want to get the value. I tried several things but nothing works unless I convert it into a char array.

For example:

c = {"test","test1"} x = strcat("x",c(1,1))

This will store a new cell in the variable x. I just want a string...

5
  • We are not omniscient. Please provide a functioning example and what you have tried already. Commented Dec 14, 2015 at 11:15
  • 1
    if you have stuff on a cell array, and you want to take one of its cells into a "normal" variable, you have to index with {} as in a = your_cell_array{1} Commented Dec 14, 2015 at 11:18
  • 4
    Please read the documentation. See Access Data in a Cell Array Commented Dec 14, 2015 at 11:21
  • 1
    c(1,1) is a cell array, when you input cell arrays strcat returns cell arrays. Commented Dec 14, 2015 at 11:24
  • To expand on Daniel's comment: use x = strcat("x",c{1,1}) to feed strcat with strings (not with a cell as second input) and it will produce a string Commented Dec 14, 2015 at 12:18

1 Answer 1

2

If you just want one of the cell elements as a string, you access the string using the normal cell operations:

c = {"test","test1"};
x = c{1};  %gets the first string
y = c{2};  %gets the second string

But, if you want to get all of the strings out of the cell array, you can use strvcat, which will vertically concatenate the strings into a matrix, padding with white space as needed:

c = {"test","test1"};
x = strvcat(c);  %returns matrix, padded with whitespace
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.