Thank you so much, dpb~~
1. Still don't see "3"
>> c={'xxx'}; whos c
Name Size Bytes Class Attributes
c 1x1 66 cell
It doesn't say anything about "3"...
2.
case {'linear','bilinear'}, disp('Method is linear') is nice! Nice example why {} is useful.
3.
>> methods=strvcat('linear','bilinear','cubic','nearest','bicubic')
methods =
linear
bilinear
cubic
nearest
bicubic
>> for idx=1:size(methods,1)
method=methods(idx);
disp(method);
%insert above SWITCH construct here
...
end
l
b
c
n
b
So methods(idx) only gets the first letter in each line.
I see. I remember I read in the help, in the above case, methods in a matrix with blanks to make it a rectangular matrix.
>> size(methods,1)
ans =
5
>> size(methods,2)
ans =
8
So it's 5 lines, 8 columns. Because the longest word in each line is 8 letters.
To refer to each word, method(line_number) doesn't work. We need method(line_number,:)
>> methods(2)
ans =
b
>> methods(2,:)
ans =
bilinear
A easier way (to me) to deal with that may be this:
>>methods={'linear','bilinear','cubic','nearest','bicubic'}
methods =
'linear' 'bilinear' 'cubic' 'nearest' 'bicubic'
>> methods{1}
ans =
linear
It's so nice to discuss with you. Thank you again~
btw, I'm now dying doing Fourier transform things. Are you also familiar with this? I can post a message and email you to tell you, if you're interested.
dpb <none@non.net> wrote in message <jn6p9u$gbl$1@speranza.aioe.org>...
> On 4/24/2012 12:31 PM, Yuji wrote:
> > Thank you for the detailed explanation, dpb!
> >
> > Still wanna check about two things with you.
> > 1.
> > Quote      >> c={'xx'}; % a single cell array
> > >> whos c
> > Name Size Bytes Class
> > c 1x1 96 cell array
> > Grand total is 3 elements using 96 bytes
> > Quote end     
> > Why it's 3 elements?
>
> One for the cell, two for the contents. To see this try
> c={'xxx'};
> whos c
>
> > 2.
> > Quote      s='RGB';
> > for idx=1:length(s)
> > switch s(idx)
> > case {'R'}
> > disp('RED')
> ...
>
> > Quote end     
> > This code works. When i remove the {}, it still works.
> > s='RGB';
> > for idx=1:length(s)
> > switch s(idx)
> > case 'R'
> > disp('RED')
> ...
>
> > Why here Matlab treat 'R' and {'R'} the same thing?
> ...
>
> 'Cuz they are the same thing as literals. I use the {} as a habit
> consider the following snippet (from doc on SWITCH)
>
> method='linear';
>
> switch lower(method)
> case {'linear','bilinear'}, disp('Method is linear')
> case 'cubic', disp('Method is cubic')
> case 'nearest', disp('Method is nearest')
> otherwise, disp('Unknown method.')
> end
> Method is linear
>
> Now try it removing the {} around the CASE conditions and see what happens.
> >> switch lower(method)
> case 'linear','bilinear', disp('Method is linear')
> case 'cubic', disp('Method is cubic')
> case 'nearest', disp('Method is nearest')
> otherwise, disp('Unknown method.')
> end
> ans =
> bilinear
> Method is linear
> >>
>
> Can you see where the 'bilinear' output came from?
>
> The other thing that's different is consider the above except let's
> define the possible methods as
>
> methods=strvcat('linear','bilinear','cubic','nearest','bicubic')
>
> and we tried something like
>
> for idx=1:size(methods,1)
> method=methods(idx);
> %insert above SWITCH construct here
> ...
> end
>
> Try that. What mod need to make to get that to work?
>
> On the other hand, what if we used
>
> methods={'linear';'bilinear';'cubic';'nearest';'bicubic'};
>
> instead?
>
> 
