I have a 1D logical vector, a cell array, and a string value I want to assign.
I tried "cell{logical} = string" but I get the following error:
The right hand side of this assignment has too few values to satisfy
the left hand side.
Do you have the solution?
Always specify the row first and column second. To refer to multiple elements of an array, use the colon ':' operator, which allows you to specify a range of elements using the form 'start:end'. The colon alone, without start or end values, specifies all the elements in that dimension.
The deal function is an adapter that allows cell arrays and structure arrays to be cross assigned to each other. It gets its name from the metaphor of dealing a round of cards.
Use comma-separated lists to get multiple variables in the left hand side of an expression. You can use deal() to put multiple assignments one line. [x,y] = deal(cell(4,8), cell(4,8));
You don't actually need to use deal
.
a = cell(10,1); % cell array
b = rand(1,10)>0.5; % vector with logicals
myString = 'hello'; % string
a(b) = {myString};
Looking at the last line: on the left hand side we are selecting a subset of cells from a
and saying that they should all equal the cell on the right hand side, which is a cell containing a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With