how to compare array with matlab

前端 未结 2 1033
生来不讨喜
生来不讨喜 2021-01-24 16:20

I would like to comapre two arrays of strings how could I affect the following values to a,b,c,d , when I try as below, I go

2条回答
  •  星月不相逢
    2021-01-24 16:59

    Mistake 1:

    = is the assignment operator.

    The comparison operator is ==.


    Mistake 2:

    MATLAB arrays don't generally hold strings. They hold numbers or single characters.

    >> b = ['a','0','10','20']
    
    b =
    
    a01020
    

    To see why [a,b,c,d] = ['a','0','10','20'] doesn't work, consider this:

    >> [a,b,c,d] = 'a01020'
    ??? Too many output arguments.
    

    You're trying to put six characters into four buckets. Not going to work.

    You might have meant to create a cell array:

    >> c = {'a','0','10','20'}
    
    c = 
    
        'a'    '0'    '10'    '20'
    

    Matlab arrays are numerical matrices, not general-purpose list containers.

提交回复
热议问题