Why does the sum of S1 AND S2 ?

S1=[23.6000 58.4000 47.4000 101.7000 29.9000 36.8000] S2=[23.6000 58.4000 47.4000 67.1000 29.9000 71.4000]
c=0; while (S1~=S2)
c=S1+S2
end
c
Why does the sum of S1 AND S2 ?
Thanks.

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 8 Nov 2013
Edited: Azzi Abdelmalek on 8 Nov 2013
Maybe you want
S1=[23.6000 58.4000 47.4000 101.7000 29.9000 36.8000]
S2=[23.6000 58.4000 47.4000 67.1000 29.9000 71.4000]
c=0;
while ~isequal(S1,S2)
c=S1+S2
end

2 Comments

I think you misunderstand how while works. It cannot loop over the elements of S1 as you have written it.
I don't know what you want. Can you explain?

Sign in to comment.

Walter Roberson
Walter Roberson on 8 Nov 2013
Your while loop does not change S1 or S2, so the body will either not be done at all (if the condition does not hold at the beginning) or will be done repeatedly without end.

4 Comments

THIS IS MY FULL CODE, i don't know to set the while loop, when i have T=6; while not count correctly
clear,clc
MON = [2.8 3.6 17.2;
5.4 8.3 15.8;
2.5 3.2 17.6;
9.9 10.7 13.6;
5.5 8.9 15.5;
9.7 11 13.9;
2.3 3.9 17.9;
5.7 8.1 15.1;
9.4 10.5 13;
9.9 13.2 13.7];
[m,n]=size(MON)
T=input('Zadaj počet typickych bodov :')%uzivatel zada koľko chce mať typickych bodov
for i=1:T %Pociatocne typicke body
TAZ=MON(1:T,:);
end
TAZ
[r,s]=size(TAZ)%rozmery TAZ
Z=cell(1,T)%vytvorenie zhlukov
z=1;
for i=1:m
for j=1:r
B = MON(i,:);
Z1(j)= euklid6(TAZ(j,:),B);%euklidovska vzdialenost
end
Z1
minD = min([Z1]);%minimalna hodnota
[i_min,j_min]=find(Z1==minD);%indexacia minimalnej hodnoty
[e,f]=size(Z1);
%postupne ukladanie podla prislusnosti objektu do zhlukov
for h=1:f
if (Z1(h) == Z1(j_min))
Z{h}{z}=B;
z=z+1;
end
end
end
Z;
d1=length(Z)
for i=1:d1 %zmaze prazdne miesta v poli
Z{i}(cellfun(@isempty,Z{i})) = [];
end
Z
[z1,z2]=size(Z)
Znew={};%nove pole
for j=1:z2
S1(j)=sucet1(Z(j));
end
S1
S2=0;
iter=1;
while (S1(:,:)~=S2(:,:)) % this while loop is not correctly
[t1,t2]=size(Z);%rozmery Z
for j=1:t2
d(j,:)=tazisko6(Z(j));%vypocet noveho taziska
end
d
[x,y]=size(d)%rozmery d
w=1;
for i=1:m
for j=1:x
B = MON(i,:);
Z1(j)= euklid6(d(j,:),B);%euklidovska vzdialenost
end
Z1
minD = min([Z1]);%minimalna hodnota
[i_min,j_min]=find(Z1==minD);%indexacia minimalnej hodnoty
[e,f]=size(Z1);%rozmery Z1
%postupne ukladanie podla prislusnosti objektu do zhlukov
for h=1:f
if (Z1(h) == Z1(j_min))
Znew{h}{w}=B;
w=w+1;
end
end
end
Znew;
d2=length(Znew);%zmeria dlzku pola
for i=1:d2 %zmaze prazdne miesta v poli
Znew{i}(cellfun(@isempty,Znew{i})) = [];
end
Znew;
Z=Znew
[b1,b2]=size(Z);
for j=1:z2
S2(j)=sucet1(Z(j));
end
S2
iter=iter+1;
end
clear,clc
function [d] = tazisko6(A)
%%[d] = tazisko6(A)
%
% Tazisko jednotlivych zhlukov(centroid)
d1=length(A);
d2 =length(A{1});
s=0;
for i=1:d1
for j=1:d2
s=s+(A{i}{j});
end
if d2~=1
d=s/d2;
else
d=s;
end
end
function [ d] = euklid6( A,B )
%%[d] = euklid(A,B)
%
% Euklidovska vzdialenost bodov
[hA,tA]=size(A);
[hB,wB]=size(B);
if hA==1&hB==1
d=sqrt(dot((A-B),(A-B)));
else
C=[ones(1,hB);zeros(1,hB)];
D=flipud(C);
E=[ones(1,hA);zeros(1,hA)];
F=flipud(E);
G=A*C;
H=A*D;
I=B*E;
J=B*F;
d=sqrt((G-I').^2+(H-J').^2);
end
end
function [ S1 ] = sucet1( Z1 )
%%S1=sucet(Z1)
n1=length(Z1);
n2=length(Z1{1});
u=0;
for i=1:n1
for j=1:n2
u=u+sum(Z1{i}{j});
end
S1(i)=u;
end
end
THANKS
Okay, in that code your while does appear to be changing S2, at least under some conditions. (I have not tried to figure out what the code is intended to do.)
I would suggest though that you read,
Tomas
Tomas on 8 Nov 2013
Edited: Tomas on 8 Nov 2013
i don't understand english very well :)
A = 0.3 - 0.2 - 0.1;
B = 0;
if A == B
disp('the two are equal')
else
disp('the two are not equal')
end
if abs(A-B) < eps(0.3)
disp('the two are approximately equal')
else
disp('the two are not approximately equal')
end
Do not compare floating point numbers for equality.
Also, you are comparing two arrays. Read the documentation for "if"
An evaluated expression is true when the result is nonempty and contains all nonzero elements (logical or real numeric). Otherwise, the expression is false.

Sign in to comment.

Asked:

on 8 Nov 2013

Commented:

on 9 Nov 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!