Search All of the Math Forum:

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

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

 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

"NatasaSI " <mojih50@yahoo.it> wrote in message
news:l33nj5\$pu3\$1@newscl01ah.mathworks.com...
> 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
like:

S =
'abcde'

and one displayed like:

T =
abcde

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:
>>>length(vincita)
> ans = 5
>>>length(data.textdata(1))
> 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
array.

> 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

> 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
combination with non-cell arrays.

--
Steve Lord
slord@mathworks.com