Assign a value to multiple cells in matlab

前端 未结 4 1182
旧时难觅i
旧时难觅i 2020-12-30 05:38

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         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 06:23

    You can try this

    a = cell(10,1); % cell array
    b = rand(1,10)>0.5; % vector with logicals
    myString = 'hello'; % string
    
    [a{b}] = deal(myString);
    

    It results in:

    a = 
    
        'hello'
             []
             []
        'hello'
        'hello'
             []
        'hello'
        'hello'
             []
             []
    

提交回复
热议问题