我有一个1D逻辑向量,一个单元格数组和一个我想要分配的字符串值.
我试过"cell {logical} = string"但是我收到以下错误:
The right hand side of this assignment has too few values to satisfy
the left hand side.
Run Code Online (Sandbox Code Playgroud)
你有解决方案吗?
小智 18
你实际上并不需要使用deal.
a = cell(10,1); % cell array
b = rand(1,10)>0.5; % vector with logicals
myString = 'hello'; % string
a(b) = {myString};
Run Code Online (Sandbox Code Playgroud)
查看最后一行:在左侧,我们从中选择一个单元格,a并说它们应该都等于右侧的单元格,这是一个包含字符串的单元格.
H.M*_*ter 14
你可以试试这个
a = cell(10,1); % cell array
b = rand(1,10)>0.5; % vector with logicals
myString = 'hello'; % string
[a{b}] = deal(myString);
Run Code Online (Sandbox Code Playgroud)
它导致:
a =
'hello'
[]
[]
'hello'
'hello'
[]
'hello'
'hello'
[]
[]
Run Code Online (Sandbox Code Playgroud)