Cell Array manipulation (matlab)

AI Thread Summary
To generate the string 'Cal Golden Bears' from the cell array A in MATLAB, the command strjoin can be used effectively. The user initially extracted elements with A(1:3) but struggled with concatenation into a single string. By applying strjoin on A(1:3), the correct output is achieved. Additionally, there was a discussion about formatting the output with single quotes, suggesting the use of concatenation. Ultimately, strjoin provides a straightforward solution for combining cell array elements into a single string.
gfd43tg
Gold Member
Messages
947
Reaction score
48

Homework Statement


Write a line of MATLAB code that uses the cell array A to generate the string 'Cal Golden Bears'

Homework Equations


The Attempt at a Solution


Code:
  A = {'Cal', 'Golden', 'Bears', [5 7], {[1 2 3 4]}}

A = 

    'Cal'    'Golden'    'Bears'    [1x2 double]    {1x1 cell}

The furthest I've gotten so far is A(1:3)
Code:
 A(1:3)

ans = 

    'Cal'    'Golden'    'Bears'
But I don't know how to concatenate them so that they are all one string. I think I am just supposed to use one command that can create the string.
 
Physics news on Phys.org
I never heard of that command before. Is there anyway by manipulating the cell array sort of how I did with A(1:3)?

Code:
strjoin(A(1:3))

ans =

Cal Golden Bears

Still misses the ' '
 
cant you then say x = "'" + strjoin(...) + "'" ?

note: I quoted the single quote not sure if you'll need to backslash it too? ie "\'"
 
Back
Top