What is the difference between ( ) and [ ] format in matlab? how can i change the one format to another one?

Dear Sir/MAdam,
What is the difference between ( ) and [ ] format in matlab? how can i change the one format to another one?
[rangr]=split(rangr(x,:),gsize1);
[rangg]=split(rangg(x,:),gsize1);
[rangb]=split(rangb(x,:),gsize1); this is function
I want get the result format for only this ( ) format, not this [] format.. so how can i convert it.. please any one help to me.
Edit [11 Sep 2012, 12:04 BST - OK] Merged from duplicate
Dear Sir/MAdam, Please read out my following codes . I got a rang, meanran and varran values for ( ) this format. But I got the result for rang ,meansrang,varsrang values for [ ] format. THis method is correct or not..?
for i1=1:gsize:nr
for j1=1:gsize:nc
l=1;
for x=i1:1:i1+(gsize-1)
for y=j1:1:j1+(gsize-1)
rang1(k,l)=c(x,y);
l=l+1;
end
end
dr=double(rang1(k,:));
meanran(k)=mean(dr);
varran(k,:)=var(dr);
k=k+1;
end
end
###################################
[rang]=qtsplit(rang1(i1,:),gsize1);
for x=1:1:4
dr=double(rang(x,:));
meansrang(x)=mean(dr(1,:));
varsran(x)=var(dr(1,:));
So I got the Result in different formate and Error image also. how can i rectify that formate?
(rang2)=[rang] possible or not? how can i change the type[] to ( ). Any one pleas help to my question.
Thank you.

5 Comments

Opps -- Oleg, your merge happened to delete the Answer I gave to the duplicate!
Really sorry Walter.
When I opened it there was no answer and I usually refresh before doing such operations and I forgot this time.
I will ask TMW to retrieve your answer.
Thanks, but don't bother Oleg. I don't think they can retrieve deleted messages anyhow, and it was probably too new to have been backed up.
I sent an email, we'll see. I recall that in one of the updates to ANSWERS they said they don't delete posts from the DB but flag them.

Sign in to comment.

 Accepted Answer

If SPLIT is a function, then () is needed. This is the syntax function(parameter1, parameter2).
[] concatenates. Simply try
[1, 2, 3]
in the command window and you will see.
From this question, I do not see a format that can be changed. () and [] are used for different purposes.

1 Comment

ok sir thank you, But above my coding I got the result for both [] and (). but the men image of that () result is ok. But the mean image of [] that result is too bad. So how can I change the format of [] to ().

Sign in to comment.

More Answers (1)

You cannot use () to surround output variables in MATLAB; it just isn't allowed. You need to use [] instead. [] hints at building a list.
[variable] = function_call() %allowed
(variable) = function_call() %not allowed
In expressions, [] is used for building matrices.
[1 2; 3 4] %builds a two by two array
In expressions, () is used for array subscripting, such as a(3), and is also used to control the order of operations, such as ((1+3)*2)

10 Comments

ok sir thank you, But above my coding I got the result for both [] and (). but the men image of that () result is ok. But the mean image of [] that result is too bad. So how can I change the format of [] to ().
Please show the two versions of the line that you have tried.
Dear Sir, My research is valuable work sir. I got error for this images sir. If correct that program sir. If you don't mind shall i send my code you mail ID sir.
tic;
% read the image
im1=imread('D:\lena.jpg');
c = im2uint8(im1);
gsize=8;
nr=512;
nc=512;
% resize the image
c=imresize(c,[nr,nr]);
% figure(2);
% imshow(c);
nc=nr;
R=c(:,:,1);
G=c(:,:,2);
B=c(:,:,3);
% split the image of the range size
k=1;
for i1=1:gsize:nr
for j1=1:gsize:nc
l=1;
for x=i1:1:i1+(gsize-1)
for y=j1:1:j1+(gsize-1)
rang1r(k,l)=R(x,y);
rang1g(k,l)=G(x,y);
rang1b(k,l)=B(x,y);
l=l+1;
end
end
drr=double(rang1r(k,:));
meanranr(k)=mean(drr);
varranr(k,:)=var(drr);
drg=double(rang1g(k,:));
meanrang(k)=mean(drg);
varrang(k,:)=var(drg);
drb=double(rang1b(k,:));
meanranb(k)=mean(drb);
varranb(k,:)=var(drb);
k=k+1;
end
end
rang1=cat(3,rang1r,rang1g,rang1b);
meanran=cat(3,meanranr,meanrang,meanranb);
varran=cat(3,varranr,varrang,varranb);
[nrr1,ncr1]=size(rang1);
% to display the mean image
n=sqrt(nrr1);l=1;
for i1=1:1:n
for j1=1:1:n
meanimg1r(i1,j1)=meanranr(l);
meanimg1g(i1,j1)=meanrang(l);
meanimg1b(i1,j1)=meanranb(l);
l=l+1;
end
end
meanimg1=cat(3,meanimg1r,meanimg1g,meanimg1b);
meanimg = uint8(round(meanimg1-1));
% figure(3);
% imshow(meanimg);
% title('Mean Image of the training');% I got a correct mean image sir
% divide the mean image into blocks
km=1;
for i1=1:gsize:n
for j1=1:gsize:n
l=1;
for x=i1:1:i1+(gsize-1)
for y=j1:1:j1+(gsize-1)
mimageranr(km,l)=meanimg1r(x,y);
mimagerang(km,l)=meanimg1g(x,y);
mimageranb(km,l)=meanimg1b(x,y);
l=l+1;
end
end
km=km+1;
end
end
mimageran=cat(3,mimageranr,mimagerang,mimageranb);
gsize1=gsize/2;
km=1;
for i1=1:gsize1:n
for j1=1:gsize1:n
l=1;
for x=i1:1:i1+(gsize1-1)
for y=j1:1:j1+(gsize1-1)
mimageran1r(km,l)=meanimg1r(x,y);
mimageran1g(km,l)=meanimg1g(x,y);
mimageran1b(km,l)=meanimg1b(x,y);
l=l+1;
end
end
km=km+1;
end
end
mimageran1=cat(3,mimageran1r,mimageran1g,mimageran1b);
llim=10;
if (gsize == 16)
nvar = 7; nvar1 = 9;
elseif (gsize == 8)
nvar = 11; nvar1 = 13;
elseif (gsize == 4)
nvar = 15; nvar1 = 17;
else
nvar = 19;
end
threshold=10;a=1;e=1;e1=1;b=1;w=1;w1=1;eno=0;
% compute the fractal code
for i1=1:1:nrr1
disp(i1);
if (varran(i1) < threshold)
% Code using mean value
label(i1)=0;
mgacoder(e)=[meanranr(i1)];
mgacodeg(e)=[meanrang(i1)];
mgacodeb(e)=[meanranb(i1)];
e=e+1;
mgacode=cat(3,mgacoder,mgacodeg,mgacodeb);
else
% code using genetic Algorithm
label(i1)=1;
[isomer alphr meanrr dom1r errr]=ga(rang1r(i1,:),mimageranr,nvar,20);
[isomeg alphg meanrg dom1g errg]=ga(rang1g(i1,:),mimagerang,nvar,20);
[isomeb alphb meanrb dom1b errb]=ga(rang1b(i1,:),mimageranb,nvar,20);
err=(errr+errg+errb)/3;
if (err < llim)
label1(w)=0;
gacoder(a,:) = [isomer alphr meanrr dom1r];
gacodeg(a,:) = [isomeg alphg meanrg dom1g];
gacodeb(a,:) = [isomeb alphb meanrb dom1b];
a=a+1;
gacode=cat(3,gacoder,gacodeg,gacodeb);
else
label1(w)=1;
[rangr]=qtsplit(rang1r(i1,:),gsize1);
[rangg]=qtsplit(rang1g(i1,:),gsize1);
[rangb]=qtsplit(rang1b(i1,:),gsize1);
for x=1:1:4
drr=double(rangr(x,:));
meansrangr(x)=mean(drr(1,:));
varsranr(x)=var(drr(1,:));
drg=double(rangg(x,:));
meansrangg(x)=mean(drg(1,:));
varsrang(x)=var(drg(1,:));
drb=double(rangb(x,:));
meansrangb(x)=mean(drb(1,:));
varsranb(x)=var(drb(1,:));
rang=cat(3,rangr,rangg,rangb);
meansrang=cat(3,meansrangr,meansrangg,meansrangb);
varsran=cat(3,varsranr,varsrang,varsranb);
if (varsran(x) < threshold/2)
lab(w1)=0;
mgacode1r(e1)=[meansrangr(x)];
mgacode1g(e1)=[meansrangg(x)];
mgacode1b(e1)=[meansrangb(x)];
e1=e1+1;
mgacode1=cat(3,mgacode1r,mgacode1g,mgacode1b);
else
lab(w1)=1;
[isomeqr alphqr meanrqr dom2qr errqr] = ga(rangr(x,:),mimageran1r,nvar1,40);
[isomeqg alphqg meanrqg dom2qg errqg] = ga(rangg(x,:),mimageran1g,nvar1,40);
[isomeqb alphqb meanrqb dom2qb errqb] = ga(rangb(x,:),mimageran1b,nvar1,40);
errq=(errqr+errqg+errqb)/3;
if (errq > llim)
eno=eno+1;
end
gacode1r(b,:)=[isomeqr,alphqr,meanrqr,dom2qr];
gacode1g(b,:)=[isomeqg,alphqg,meanrqg,dom2qg];
gacode1b(b,:)=[isomeqb,alphqb,meanrqb,dom2qb];
b=b+1;
gacode1=cat(3,gacode1r,gacode1g,gacode1b);
end
w1=w1+1;
end
end
w=w+1;
end
end
eno
t=toc
%decoding
% compute the mean image and display
tic
w=1;q=1;q1=1;w1=1;w2=1;p=1;p1=1;
for n=1:1:sqrt(nrr1)
for m=1:1:sqrt(nrr1)
if (label(w)==0)
dmimgr(n,m)=mgacoder(p);
dmimgg(n,m)=mgacodeg(p);
dmimgb(n,m)=mgacodeb(p);
p=p+1;
dmimg=cat(3,dmimgr,dmimgg,dmimgb);
else
if (label1(w1)==0)
dmimgr(n,m)=gacoder(q,3);
dmimgg(n,m)=gacodeg(q,3);
dmimgb(n,m)=gacodeb(q,3);
q=q+1;
dmimg=cat(3,dmimgr,dmimgg,dmimgb);
else
sumvq=0;sumvqr=0;sumvqg=0;sumvqb=0;
for i=1:4
if (lab(w2)==0)
sumvqr=sumvqr+mgacode1r(p1);
sumvqg=sumvqg+mgacode1g(p1);
sumvqb=sumvqb+mgacode1b(p1);
p1=p1+1;
sumvq=cat(3,sumvqr,sumvqg,sumvqb);
else
sumvqr=sumvqr+gacode1r(q1,3);
sumvqg=sumvqg+gacode1g(q1,3);
sumvqb=sumvqb+gacode1b(q1,3);
q1=q1+1;
sumvq=cat(3,sumvqr,sumvqg,sumvqb);
end
w2=w2+1;
end
dmimg=sumvq/4;
end
w1=w1+1;
end
w=w+1;
end
end
cimage = uint8(round(dmimg - 1));
figure(4);
imshow(cimage);
title('Decoded Mean iMage); % I got this decoded mean image is not proper
Sir I got some block dots in MEan Image. How can I correct that Image sir. Please kindly help me sir.
When you say "block dots", do you mean "black dots" ?
Which line are you having the difficulty with () compared to [] ? And what are the two versions of the line that you have tried, and what is the difference in results for the two versions ?
The first one is Normal mean image calculation. And another one is we have to calculate the fractal value using GA algorithm then, we have to calculate the Decoded Mean image using that fractal values. First I have to calculate the Normal Mean image. No Errors all blocks are calculated. But the dmimg have to calculate the partial value. So many placed 0(zero) values accure. Whenever I have to Run this Program I have get the Different values in Mgacode1 and Gacode1 for each time. So i get the so many zero values for the dmimg so. The Docoded mean image is not get proper. The combined block values are display the black color of mean image.
Please write out the code line difference, one showing [] and the other showing () . I am still trying to solve your original question.
In the syntax
[rangr]=qtsplit(rang1r(i1,:),gsize1);
you can leave out the [] and the result will be exactly the same:
rangr=qtsplit(rang1r(i1,:),gsize1);
It appears to me that your difficulty has nothing to do with () compared to [].
Code of the form
variable(index) = expression;
sets the index'th element of "variable" to contain the value of the expression.
Code of the form
[variable] = expression;
is exactly the same as
variable = expression;
and replaces "variable" entirely, so that afterwards "variable" has only the value of the expression.
There is also code of the form
[variable1, variable2] = expression;
In that case, "expression" would normally be a function call that returns multiple outputs, with the first output being assigned to "variable1" and the second assigned to "variable2". (There are also some cases where the expression might involve cell arrays or structures instead of a function call.)
I am not familiar with the algorithms involved in your code, and it appears that for me to understand and debug it would be more work than I would be willing to do as a volunteer.
Good Morning Sir,
I have to change my code in some places, no error but i got Error image.
Ok sir I will try for correct it. Thank you for your help. If u identify that error, Please update your answer sir. Thank you

Sign in to comment.

Categories

Find more on Fractals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!