Clear Filters
Clear Filters

k=1;201;

2 views (last 30 days)
buxZED
buxZED on 1 Mar 2011
k=1;201;
What dose this mean in english?

Accepted Answer

Walter Roberson
Walter Roberson on 2 Mar 2011
As asked:
A variable named "k" is to be created. The variable is to be assigned a value. The value to be assigned is the list of numbers that is the single number 1. The ";" that follows that indicates that the result of the assignment is not to be displayed. That is the end of that bit of execution, and the rest of the line is evaluated separately. The value 201 is constructed, and as it is not used in any other way, its value is to be assigned to the default variable named "ans". The ";" that follows that indicates that the result of the assignment is not to be displayed.
But what you probably meant to ask about was
k=1:201;
with a ":" between the numbers instead of a ";". The meaning of that would be:
A variable named "k" is to be created. The variable is to be assigned a value. The value to be assigned is the list of numbers starting from 1, incrementing by 1, until the last number that is less than or equal to 201. The ';' means that the result of doing the assignment is not to be displayed.
Note that k=1:201; would have a different but related meaning if proceeded by the keyword "for", as in
for k=1:201;

More Answers (1)

Matt Fig
Matt Fig on 1 Mar 2011
It means: set the variable k to equal 1, then set the variable ans to 201, displaying nothing.
You can see this by executing these lines at the command window:
clear all,clc
k=1;201;
whos
k
ans
Now, if you had put this:
k=1:201; % Note the colon.
that would mean: set the variable k to a vector of length 201 with the elements 1 through 201, inclusive.

Categories

Find more on Visual Exploration 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!