Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Structures within For Loops

Subject: Structures within For Loops

From: Mary

Date: 5 Jun, 2013 16:59:12

Message: 1 of 17

Hello!

I'm working on populating .mat files with structs which are filled with data from xls spreadsheets.

In the spreadsheets data is listed in groups of 10, such that 10 rows correspond to one .mat I need to build.

function filter_example.m
files = dir('*.xls')
a=2
c=2
d=1
b=1
for i= 1:numel(files)

filename = files(i).name
[data,textdata,raw]=xlsread(filename)

for j = 1:numel(textdata) % for 1 through the # of rows in the sheet
    
for k = 1:10 % for the set of 10 it's pulling from
R=round(b); % I want this to change R every time it loops
R.block= data(a,1);
.
.
.

a=a+1;
d=d+1;
b=b+1;
end

name=textdata(c,1); % takes group name and saves the .mat as that group name
savefile=char(name);

save (savefile)
a=a+10;
d=d+10;
c=c+10;

end
end
end


When I run this code, it works for R(1), but it does not populate any data for R(2) or R(3) - it just overwrites itself 10 times.

How do I go about fixing this?

Thanks,

Mary

Subject: Structures within For Loops

From: dpb

Date: 5 Jun, 2013 18:25:24

Message: 2 of 17

On 6/5/2013 11:59 AM, Mary wrote:
...
> I'm working on populating .mat files with structs which are filled with
> data from xls spreadsheets.
>
> In the spreadsheets data is listed in groups of 10, such that 10 rows
> correspond to one .mat I need to build.
> function filter_example.m
> files = dir('*.xls')
> a=2
> c=2
> for i= 1:numel(files)
> filename = files(i).name
> [data,textdata,raw]=xlsread(filename)
> for j = 1:numel(textdata)
> for k = 1:10 % for the set of 10 it's pulling from
> R=round(b); % I want this to change R every time it loops
> R.block= data(a,1);
> a=a+1;
> end
> name=textdata(c,1); % takes group name as that group name
> savefile=char(name);
> save (savefile)
> a=a+10;
> c=c+10;
> end
> end
> end
>
>
> When I run this code, it works for R(1), but it does not populate any
> data for R(2) or R(3) - it just overwrites itself 10 times.
>
> How do I go about fixing this?
...

Not perfectly clear on what you're doing or the form of the data in the
spreadsheet but it appears there's apparently a spreadsheet w/ a text
field and data column after a header line (hence the starting at 2 in
the indexing?) If that's so, though, shouldn't the upper limit on the
'j' loop be length(textdata)-1 instead? I then grok wanting to divide
it into separate files in groupings of 10 per each using the string
found on the same entry.

I'm not positive of the role you want R to play but if you're trying to
build a structure array of length of the info in the spreadsheet then
you simply add elements/records by indexing the structure name. --- Oh,
as I was working thru the example below I think I fingered out the
issue--you were trying to build the array block. To do that the way you
wrote it, you wanted to preallocate an array and then load it. Then
assign it to the structure. But, it's easier done more efficiently w/
array addressing as shown below...

When you save() the file, however, by default SAVE saves the entire
workspace so each file is successively going to contain all of the
elements up to and including the current as well as all the ancillary
variables a,b,c,d,... I'd presume that's not _precisely_ the intent.

If not, you need to qualify the actual save() call w/ the data
specifically wanted to be saved.

Lastly, you don't need to do all the indexing individually, use the
array operations of Matlab. I'd cast it sotoo

N=2; % line number of initial data
L=10; % number lines to aggregate over
files = dir('*.xls')
for i= 1:length(files)
   i1=N;
   i2=i1+L-1;
   filename = files(i).name;
   [data,txt,raw]=xlsread(filename);
   for j = 1:length(textdata)-1
     R.block= data(i1:i2,1);
     save (char(txt(i1)),'R')
     i1=i1+L;
     i2=i2+L;
   end
end

Hopefully have interpreted the request...

--

Subject: Structures within For Loops

From: dpb

Date: 5 Jun, 2013 22:31:55

Message: 3 of 17

On 6/5/2013 1:25 PM, dpb wrote:
> On 6/5/2013 11:59 AM, Mary wrote:
> ...
>> I'm working on populating .mat files with structs which are filled with
>> data from xls spreadsheets.
>>
>> In the spreadsheets data is listed in groups of 10, such that 10 rows
>> correspond to one .mat I need to build.
>> function filter_example.m
>> files = dir('*.xls')
>> a=2
>> c=2
>> for i= 1:numel(files)
>> filename = files(i).name
>> [data,textdata,raw]=xlsread(filename)
>> for j = 1:numel(textdata)
>> for k = 1:10 % for the set of 10 it's pulling from
>> R=round(b); % I want this to change R every time it loops
>> R.block= data(a,1);
>> a=a+1;
>> end
>> name=textdata(c,1); % takes group name as that group name
>> savefile=char(name);
>> save (savefile)
>> a=a+10;
>> c=c+10;
>> end
>> end
>> end
>>
>>
>> When I run this code, it works for R(1), but it does not populate any
>> data for R(2) or R(3) - it just overwrites itself 10 times.
>>
>> How do I go about fixing this?
> ...
>
> Not perfectly clear on what you're doing or the form of the data in the
> spreadsheet but it appears there's apparently a spreadsheet w/ a text
> field and data column after a header line (hence the starting at 2 in
> the indexing?) If that's so, though, shouldn't the upper limit on the
> 'j' loop be length(textdata)-1 instead? I then grok wanting to divide it
> into separate files in groupings of 10 per each using the string found
> on the same entry.
>
> I'm not positive of the role you want R to play but if you're trying to
> build a structure array of length of the info in the spreadsheet then
> you simply add elements/records by indexing the structure name. --- Oh,
> as I was working thru the example below I think I fingered out the
> issue--you were trying to build the array block. To do that the way you
> wrote it, you wanted to preallocate an array and then load it. Then
> assign it to the structure. But, it's easier done more efficiently w/
> array addressing as shown below...
>
> When you save() the file, however, by default SAVE saves the entire
> workspace so each file is successively going to contain all of the
> elements up to and including the current as well as all the ancillary
> variables a,b,c,d,... I'd presume that's not _precisely_ the intent.
>
> If not, you need to qualify the actual save() call w/ the data
> specifically wanted to be saved.
>
> Lastly, you don't need to do all the indexing individually, use the
> array operations of Matlab. I'd cast it sotoo
>
> N=2; % line number of initial data
> L=10; % number lines to aggregate over
> files = dir('*.xls')
> for i= 1:length(files)
> i1=N;
> i2=i1+L-1;
> filename = files(i).name;
> [data,txt,raw]=xlsread(filename);
> for j = 1:length(textdata)-1
> R.block= data(i1:i2,1);
> save (char(txt(i1)),'R')
> i1=i1+L;
> i2=i2+L;
> end
> end
>
> Hopefully have interpreted the request...

Or, another alternative intent, perhaps???

N=2; % line number of initial data
L=10; % number lines to aggregate over
files = dir('*.xls')
for i= 1:length(files)
   i1=N;
   i2=i1+L-1;
   filename = files(i).name;
   [data,txt,raw]=xlsread(filename);
   for j = 1:length(textdata)-1
     R(j).block= data(i1:i2,1);
     save (char(txt(i1)),'R(j)')
     i1=i1+L;
     i2=i2+L;
   end
end

I've not tested whether SAVE is smart enough for the above or not--if it
doesn't know how to treat the subscript on R then you'll have to have a
temporary copy to write.

The above will do to things--it will leave you with a structure array of
nFiles size and the same number of individual files each w/ the
specified name but each file will be only a single array of length 10.

It just isn't totally clear just what you really do want so "salt to
suit"...

--

Subject: Structures within For Loops

From: Steven_Lord

Date: 6 Jun, 2013 14:55:21

Message: 4 of 17



"dpb" <none@non.net> wrote in message news:kooe8s$jvg$1@speranza.aioe.org...
> On 6/5/2013 1:25 PM, dpb wrote:
>> On 6/5/2013 11:59 AM, Mary wrote:

*snip*

> save (char(txt(i1)),'R(j)')

*more snip*

> I've not tested whether SAVE is smart enough for the above or not--if it
> doesn't know how to treat the subscript on R then you'll have to have a
> temporary copy to write.

It is not smart enough. The variable name(s) you pass into SAVE to indicate
the variables to be saved must be valid variable names, and R(j) is not a
valid variable name since parentheses are not allowed in variable names.

The MATFILE function allows you to write to pieces of an array inside a
MAT-file. You would need to modify the code slightly to make use of it, as
it doesn't support linear indexing, but otherwise I think it will do what
the OP wants.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Structures within For Loops

From: dpb

Date: 6 Jun, 2013 15:05:09

Message: 5 of 17

On 6/6/2013 9:55 AM, Steven_Lord wrote:
>
>
> "dpb" <none@non.net> wrote in message
> news:kooe8s$jvg$1@speranza.aioe.org...
>> On 6/5/2013 1:25 PM, dpb wrote:
>>> On 6/5/2013 11:59 AM, Mary wrote:
>
> *snip*
>
>> save (char(txt(i1)),'R(j)')
>
> *more snip*
>
>> I've not tested whether SAVE is smart enough for the above or not--if
>> it doesn't know how to treat the subscript on R then you'll have to
>> have a temporary copy to write.
>
> It is not smart enough. The variable name(s) you pass into SAVE to
> indicate the variables to be saved must be valid variable names, and
> R(j) is not a valid variable name since parentheses are not allowed in
> variable names.

I really didn't figure it was but was too lazy to confirm that... :)

> The MATFILE function allows you to write to pieces of an array inside a
> MAT-file. You would need to modify the code slightly to make use of it,
> as it doesn't support linear indexing, but otherwise I think it will do
> what the OP wants.

I can't really tell for sure just what it is that OP _does_ want,
precisely...hence, the couple of different alternatives and admonition
to "salt to suit". :)

--

Subject: Structures within For Loops

From: Mary

Date: 6 Jun, 2013 15:09:11

Message: 6 of 17

Thank you both for the help!

I ended up resolving my issue by using

for i = 1:10

round(i).b = etc
round(i).g = etc

The problem was in my trying to use R=round(i) to shorten how much I needed to type!

Thank you both for such intuitive and quick responses, I'll take a peek into if that save style will work or not and update this once I do!

Thanks,

Mary

Subject: Structures within For Loops

From: dpb

Date: 6 Jun, 2013 16:29:26

Message: 7 of 17

On 6/6/2013 10:09 AM, Mary wrote:
> Thank you both for the help!
>
> I ended up resolving my issue by using
>
> for i = 1:10
>
> round(i).b = etc
> round(i).g = etc
>
> The problem was in my trying to use R=round(i) to shorten how much I
> needed to type!
...

Oh...no wonder you had me confused on intent...

 >> lookfor round
...
ceil - Round towards plus infinity.
fix - Round towards zero.
floor - Round towards minus infinity.
round - Round towards nearest integer.
...

ROUND is a builtin function in Matlab; I thought you were
misunderstanding indices expressions and were (needlessly) forcing an
integer value somehow...

I strongly suggest using a different variable name instead of aliasing
the builtin function.

--

Subject: Structures within For Loops

From: Mary

Date: 6 Jun, 2013 19:52:19

Message: 8 of 17

Thank you both for the help!

I ended up resolving my issue by using

for i = 1:10

round(i).b = etc
round(i).g = etc

The problem was in my trying to use R=round(i) to shorten how much I needed to type!

Thank you both for such intuitive and quick responses, I'll take a peek into if that save style will work or not and update this once I do!

Thanks,

Mary

Subject: Structures within For Loops

From: Mary

Date: 6 Jun, 2013 20:20:09

Message: 9 of 17

dpb <none@non.net> wrote in message <koqdd3$lm6$1@speranza.aioe.org>...
> On 6/6/2013 10:09 AM, Mary wrote:
> > Thank you both for the help!
> >
> > I ended up resolving my issue by using
> >
> > for i = 1:10
> >
> > round(i).b = etc
> > round(i).g = etc
> >
> > The problem was in my trying to use R=round(i) to shorten how much I
> > needed to type!
> ...
>
> Oh...no wonder you had me confused on intent...
>
> >> lookfor round
> ...
> ceil - Round towards plus infinity.
> fix - Round towards zero.
> floor - Round towards minus infinity.
> round - Round towards nearest integer.
> ...
>
> ROUND is a builtin function in Matlab; I thought you were
> misunderstanding indices expressions and were (needlessly) forcing an
> integer value somehow...
>
> I strongly suggest using a different variable name instead of aliasing
> the builtin function.
>



Ah I sincerely apologize. I didn't realize that. My data naming was for a study convention in which round was used as a term for a subset of a trial.

Thank you for the feedback and updating regardless, it is still extremely appreciated
> --

Subject: Structures within For Loops

From: dpb

Date: 6 Jun, 2013 21:57:48

Message: 10 of 17

On 6/6/2013 3:20 PM, Mary wrote:
> dpb <none@non.net> wrote in message <koqdd3$lm6$1@speranza.aioe.org>...
...

>> ROUND is a builtin function in Matlab; I thought you were
>> misunderstanding indices expressions and were (needlessly) forcing an
>> integer value somehow...
>>
>> I strongly suggest using a different variable name instead of aliasing
>> the builtin function.
...
> Ah I sincerely apologize. I didn't realize that. My data naming was for
> a study convention in which round was used as a term for a subset of a
> trial.
> Thank you for the feedback and updating regardless, it is still
> extremely appreciated

No need for apologies--it's an easy enough thing to alias a Matlab
function (there being so many of them). The round() being on RHS was
what had me going on trying to figure out the intent...since you didn't
actually do the assignment in the sample code it wasn't aliasing
(unless, of course, you'd done it in earlier code not posted in the real
thing).

Then how about naming it

notSquare(i).field % ? <VBG>

Glad to help; the solution apparently was/is essentially my second try...

--

Subject: Structures within For Loops

From: Nasser M. Abbasi

Date: 6 Jun, 2013 22:27:44

Message: 11 of 17

On 6/6/2013 4:57 PM, dpb wrote:
>
>
> No need for apologies--it's an easy enough thing to alias a Matlab
> function (there being so many of them).

This is something that I find most annoying in Matlab. Yet, the solution
to this was easy, if they have thought about it when Matlab was
designed.

Mathematica solved this problem very easily and well from day one. In
Mathematica, all commands, functions and symbols that are part
of the system start with Uppercase and are also protected from being
redefined by mistake (unless one explicitly redefine it, but then
it won't be by mistake).

This has 2 big advantages:

1) User can't redefine/overwrite a system function name by accident.

I can use the name 'plot' or 'i' or 'sin' in Mathematica without
having to worry about it. It starts with lower case, so I know
I am not redefining a system command by mistake and do not
have to keep checking, like with Matlab, if this name is part
of the system, or any of the other 100 toolboxes out there.

2) When one reads code, they can see immediately which name/function/symbol
is a user one and which is part of the system. It is also now common
practice in Mathematica community to write ones own code to always
use lower case first letter for variables and function names.

Mathematica also has packages, which provide a name space
to add additional name space protection around user functions and
names. I wish Matlab has something like this. Then one can just
write my::plot(x) or whatever. A light weight name space
mechanism for this purpose.

Anyway, too late to do anything about it for Matlab I suppose. It
is just too bad, because this really was easy to do right early on,
but they dropped the ball.

--Nasser
sorry, I did not meant to change the subject, just could not help it :)

Subject: Structures within For Loops

From: dpb

Date: 6 Jun, 2013 22:38:44

Message: 12 of 17

On 6/6/2013 5:27 PM, Nasser M. Abbasi wrote:
...

> Anyway, too late to do anything about it for Matlab I suppose. It
> is just too bad, because this really was easy to do right early on,
> but they dropped the ball.
>
> --Nasser
> sorry, I did not meant to change the subject, just could not help it :)

Well, you're a little harsh in judgment given the difference in time
between the incipient development of Matlab vis a vis Mathematica.
There's at least 10 yr difference in things that look remotely like the
present versions, but the seeds for Matlab were being planted probably
20 yr before that.

Expecting prescience in such minutiae given the early roots of Matlab is
simply asking too much for the times and computing of the day...

--

Subject: Structures within For Loops

From: Nasser M. Abbasi

Date: 6 Jun, 2013 23:15:01

Message: 13 of 17

On 6/6/2013 5:38 PM, dpb wrote:

>
> Well, you're a little harsh in judgment given the difference in time
> between the incipient development of Matlab vis a vis Mathematica.
> There's at least 10 yr difference in things that look remotely like the
> present versions, but the seeds for Matlab were being planted probably
> 20 yr before that.
>
> Expecting prescience in such minutiae given the early roots of Matlab is
> simply asking too much for the times and computing of the day...
>

I am not a computer language historian, but a quick googling
shows original of Mathematica around 1980:

http://www.wolfram.com/company/scrapbook/#preWRI_SMPManual

"December 1980: The ancestor of Mathematica takes shape...
The first draft documentation for Wolfram's SMP system..."

"Sept. 1986: The first days of Mathematica design."

and

http://www.mathworks.com/company/newsletters/articles/the-origins-of-matlab.html

says

"In the late 1970s, following Wirth’s methodology, I
used Fortran and portions of LINPACK and EISPACK to
develop the first version of MATLAB. "

Also, as you know, there was a complete re-write of Matlab
in C in 1981:

"When IBM announced their first PC in August, 1981, Jack
quickly anticipated the possibility of using MATLAB and
the PC for technical computing. He and colleague Steve
Bangert reprogrammed MATLAB in C and added M-files,
toolboxes, and more powerful graphics."

So, they are in the same time frame, may be 3-5 years
or so if you prefer. Is that such a huge laps of time?

But that is not here or there. The idea of reserved
commands and functions has been known for much longer
before that. another quick googling shows for example
that smalltalk-80 has reserved words

http://en.wikipedia.org/wiki/Smalltalk

"In fact, only six "keywords" are reserved in
Smalltalk: true, false, nil, self, super, and thisContext"

Appeared in 1972 (development began in 1969)

I am sure if I search more, will find languages that
had the concept of reserved words and commands in
themeven before that. This idea is not rocket science
really, folks 30 years ago should have known about
it :)

--Nasser

Subject: Structures within For Loops

From: Yair Altman

Date: 7 Jun, 2013 00:13:11

Message: 14 of 17

"Nasser M. Abbasi" wrote in message <kor2cv$is8$1@speranza.aioe.org>...
[snip]
> Mathematica also has packages, which provide a name space
> to add additional name space protection around user functions and
> names. I wish Matlab has something like this. Then one can just
> write my::plot(x) or whatever. A light weight name space
> mechanism for this purpose.


Matlab also has packages:
http://www.mathworks.com/help/matlab/matlab_oop/scoping-classes-with-packages.html


Yair Altman
http://UndocumentedMatlab.com

Subject: Structures within For Loops

From: dpb

Date: 7 Jun, 2013 14:12:06

Message: 15 of 17

On 6/6/2013 6:15 PM, Nasser M. Abbasi wrote:
...

> But that is not here or there. The idea of reserved
> commands and functions has been known for much longer
> before that. another quick googling shows for example
...

> ... This idea is not rocket science
> really, folks 30 years ago should have known about
> it :)

OK, I'll let you be the one who tells Cleve he's a moron and should have
spent his time researching computer sci literature instead of just
sitting down and beginning to write Matlab while also doing his "day job".

Sheesh! What unmitigated gall of youth. :(

--

Subject: Structures within For Loops

From: Steven_Lord

Date: 7 Jun, 2013 15:25:20

Message: 16 of 17



"Nasser M. Abbasi" <nma@12000.org> wrote in message
news:kor55k$p71$1@speranza.aioe.org...
> On 6/6/2013 5:38 PM, dpb wrote:
>
>>
>> Well, you're a little harsh in judgment given the difference in time
>> between the incipient development of Matlab vis a vis Mathematica.
>> There's at least 10 yr difference in things that look remotely like the
>> present versions, but the seeds for Matlab were being planted probably
>> 20 yr before that.
>>
>> Expecting prescience in such minutiae given the early roots of Matlab is
>> simply asking too much for the times and computing of the day...
>>
>
> I am not a computer language historian, but a quick googling
> shows original of Mathematica around 1980:
>
> http://www.wolfram.com/company/scrapbook/#preWRI_SMPManual
>
> "December 1980: The ancestor of Mathematica takes shape...
> The first draft documentation for Wolfram's SMP system..."
>
> "Sept. 1986: The first days of Mathematica design."
>
> and
>
> http://www.mathworks.com/company/newsletters/articles/the-origins-of-matlab.html
>
> says
>
> "In the late 1970s, following Wirths methodology, I
> used Fortran and portions of LINPACK and EISPACK to
> develop the first version of MATLAB. "
>
> Also, as you know, there was a complete re-write of Matlab
> in C in 1981:
>
> "When IBM announced their first PC in August, 1981, Jack
> quickly anticipated the possibility of using MATLAB and
> the PC for technical computing. He and colleague Steve
> Bangert reprogrammed MATLAB in C and added M-files,
> toolboxes, and more powerful graphics."
>
> So, they are in the same time frame, may be 3-5 years
> or so if you prefer. Is that such a huge laps of time?

In software development? It can be. Five years ago was 2008, and there have
been many changes to MATLAB (and our other products) since then.

The rest of the statements in this post hypothesizing about the design
decisions made when I was ... well, MUCH younger are just that: my guesses
about what happened back then.

My guess is that one of the requirements of the rewrite was to try to break
as few of the programs that Cleve had written as possible. If you look
earlier in the article you cited, Cleve's programs used functions named
ones, svd, atan, sin, and plot. I suspect Cleve would have complained (I can
almost hear it in my mind's ear) if Jack and Steve had tried to convince him
to use Svd or Sin instead of svd and sin.

> But that is not here or there. The idea of reserved
> commands and functions has been known for much longer
> before that. another quick googling shows for example
> that smalltalk-80 has reserved words
>
> http://en.wikipedia.org/wiki/Smalltalk
>
> "In fact, only six "keywords" are reserved in
> Smalltalk: true, false, nil, self, super, and thisContext"
>
> Appeared in 1972 (development began in 1969)

MATLAB does have reserved words. The list is smaller than most people think,
though.

http://www.mathworks.com/help/matlab/ref/iskeyword.html

You can't create your own function named FOR, for example, and expect it to
be called. [Like most rules this has an exception, and that is END; you can
overload END for a class, but that's because END is used in two very
different ways in MATLAB: to end loop/conditional/control flow blocks and to
refer to the final index in a particular dimension or dimensions in an
indexing expression. The overloaded END method is used for the latter.]

> I am sure if I search more, will find languages that
> had the concept of reserved words and commands in
> themeven before that. This idea is not rocket science
> really, folks 30 years ago should have known about
> it :)

I haven't used the first versions of MATLAB, but I suspect they did. Their
choice of what should be reserved and what should not was different.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Structures within For Loops

From: dpb

Date: 9 Jun, 2013 14:54:58

Message: 17 of 17

On 6/7/2013 10:25 AM, Steven_Lord wrote:
>
>
> "Nasser M. Abbasi" <nma@12000.org> wrote in message
> news:kor55k$p71$1@speranza.aioe.org...
>> On 6/6/2013 5:38 PM, dpb wrote:
>>
>>>
>>> Well, you're a little harsh in judgment given the difference in time
>>> between the incipient development of Matlab vis a vis Mathematica.
>>> There's at least 10 yr difference in things that look remotely like the
>>> present versions, but the seeds for Matlab were being planted probably
>>> 20 yr before that.
>>>
>>> Expecting prescience in such minutiae given the early roots of Matlab is
>>> simply asking too much for the times and computing of the day...
>>>
>>
>> I am not a computer language historian, but a quick googling
>> shows original of Mathematica around 1980:
>>
>> http://www.wolfram.com/company/scrapbook/#preWRI_SMPManual
>>
>> "December 1980: The ancestor of Mathematica takes shape...
>> The first draft documentation for Wolfram's SMP system..."
>>
>> "Sept. 1986: The first days of Mathematica design."
>>
>> and
>>
>> http://www.mathworks.com/company/newsletters/articles/the-origins-of-matlab.html
>>
>>
>> says
>>
>> "In the late 1970s, following Wirth’s methodology, I
>> used Fortran and portions of LINPACK and EISPACK to
>> develop the first version of MATLAB. "
>>
>> Also, as you know, there was a complete re-write of Matlab
>> in C in 1981:
>>
>> "When IBM announced their first PC in August, 1981, Jack
>> quickly anticipated the possibility of using MATLAB and
>> the PC for technical computing. He and colleague Steve
>> Bangert reprogrammed MATLAB in C and added M-files,
>> toolboxes, and more powerful graphics."
>>
>> So, they are in the same time frame, may be 3-5 years
>> or so if you prefer. Is that such a huge laps of time?
>
> In software development? It can be. Five years ago was 2008, and there
> have been many changes to MATLAB (and our other products) since then.
>
> The rest of the statements in this post hypothesizing about the design
> decisions made when I was ... well, MUCH younger are just that: my
> guesses about what happened back then.
>
> My guess is that one of the requirements of the rewrite was to try to
> break as few of the programs that Cleve had written as possible. If you
> look earlier in the article you cited, Cleve's programs used functions
> named ones, svd, atan, sin, and plot. I suspect Cleve would have
> complained (I can almost hear it in my mind's ear) if Jack and Steve had
> tried to convince him to use Svd or Sin instead of svd and sin.
>
>> But that is not here or there. The idea of reserved
>> commands and functions has been known for much longer
>> before that. another quick googling shows for example
>> that smalltalk-80 has reserved words
>>
>> http://en.wikipedia.org/wiki/Smalltalk
>>
>> "In fact, only six "keywords" are reserved in
>> Smalltalk: true, false, nil, self, super, and thisContext"
>>
>> Appeared in 1972 (development began in 1969)
>
> MATLAB does have reserved words. The list is smaller than most people
> think, though.
>
> http://www.mathworks.com/help/matlab/ref/iskeyword.html
>
> You can't create your own function named FOR, for example, and expect it
> to be called. [Like most rules this has an exception, and that is END;
> you can overload END for a class, but that's because END is used in two
> very different ways in MATLAB: to end loop/conditional/control flow
> blocks and to refer to the final index in a particular dimension or
> dimensions in an indexing expression. The overloaded END method is used
> for the latter.]
>
>> I am sure if I search more, will find languages that
>> had the concept of reserved words and commands in
>> themeven before that. This idea is not rocket science
>> really, folks 30 years ago should have known about
>> it :)
>
> I haven't used the first versions of MATLAB, but I suspect they did.
> Their choice of what should be reserved and what should not was different.

There are those who argue that reserved words is _a_bad_thing_ (r).
Fortran, for example has no reserved words; everything is interpreted in
context. There are KEYWORDS that have specific meanings but they are
context-sensitive, not reserved.

So something like the following is legal(+) (albeit certainly unwise) in
Fortran

   if(if==then) if=if*then

where the first use of the word IF refers to the keyword for a selection
control structure, while the other uses refer to a variable named IF;
likewise, THEN is used in the context of a variable in this statement.

Of course, the difference is that in Fortran, the assignment/use of
IF/THEN as variables doesn't overload an operator so that one can still
write IF constructs that behave as expected.

There are tradeoffs as always; Nasser seems to tend to have very little
breadth in vision--it's "his way or the highway" and facts and/or
historical antecedents don't have any role in Monday-morning quarterbacking.

(+) There have been some Fortran compilers in the past at least for
which the example fails because the vendor took the cheap way out in
implementation and did implement parsing by making at least some
keywords reserved. This means when one ran into a problem such as the
above, it was the compiler which was broken, not the code. Again,
"legal" doesn't imply "wise".

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us