The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: difference between ABCDE and 'ABCDE'
Replies: 2   Last Post: Oct 9, 2013 10:41 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 2,237
Registered: 9/26/13
Re: difference between ABCDE and 'ABCDE'
Posted: Oct 9, 2013 10:28 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"NatasaSI " <> wrote in message
> Hi,
> can someone explain me the difference between this:
> data.textdata(1) = 'SSSSS' and vincita = OOSZB?

The first will error, the second will error unless you have a function named
OOSZB in the current directory or on the path.

If you're asking about the difference between a variable that is displayed

S =

and one displayed like:

T =

the difference is that S is a cell array with one cell and that cell
contains a character array (string.)

>> S = {'abcde'}

while T is a plain old character array (string.)

>> T = 'abcde'

Note the extra curly braces in the definition of S.

> I notice a difference in length:
> ans = 5
> ans= 1

Yes. In the example above, T is a 1-by-5 char array since it has 5
characters. S is a 1-by-1 cell array, and that cell contains a 1-by-5 char

> I write this:
> zreb=ones(simulation_length,1);
> vincita=ones(simulation_length,1);
> for i= 1:simulation_length
> k1= round((length(r1)-a).*rand(1,1)+a);

Use RANDI here instead of scaling and rounding RAND.

> k2= round((length(r2)-a).*rand(1,1)+a);
> k3= round((length(r3)-a).*rand(1,1)+a);
> k4= round((length(r4)-a).*rand(1,1)+a);
> k5= round((length(r5)-a).*rand(1,1)+a);
> combination=[k1 k2 k3 k4 k5];
> vincita=[r1(k1) r2(k2) r3(k3) r4(k4) r5(k5)];
> for i=1:100
> if vincita=data.textdata(i,1) % PROBLEM!!!!

Yes, this is a problem for two reasons.

1) The = operator is for assignment. The == operator is for equality
testing. You can't perform assignment inside the condition of an IF
statement, but you can do equality testing.
2) If vincita is not exactly the same size as data.textdata(i, 1) [and
neither is scalar] the == operator will error. Try:

[1 1] == [1 1 1]

To solve this, use ISEQUAL instead; ISEQUAL just returns false if the two
quantities you're comparing are different sizes.

3) A string and a cell array containing that same string are not equal. If
you define S and T using the code from the top of my reply, isequal(S, T)
returns false. You could reach into the cell array to extract out the
string: isequal(S{1}, T) returns true. Alternately, if you're trying to
locate a certain string inside a cell array of strings, use the ISMEMBER
function instead of the loop.

> zreb(i)=f_final(i,8)
> end
> end
> end
> a prog gives me this error:
> The expression to the left of the equals sign is not a valid target for an
> assignment.

That's the first reason I listed above.

> Can someone have a solution? Which command i have to use to change length?

That second question is the wrong question. See the documentation for cell
arrays if you want more information about how to work with them in
combination with non-cell arrays.

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.