disp (' save and load')
save and load
pwd
ans =
/Users/mweeks/Documents/MATLAB
c = cos(2*pi*(1:180)/180);
s = sin(2*pi*(1:180)/180);
who
Your variables are:
ans c s
whos
Name Size Bytes Class Attributes
ans 1x30 60 char
c 1x180 1440 double
s 1x180 1440 double
save testsave
exit
whos
load testsave.mat
whos
Name Size Bytes Class Attributes
ans 1x30 60 char
c 1x180 1440 double
s 1x180 1440 double
edit add2sortedlist.m
a = addd2sortedlist([1, 7, 10], 5);
{Undefined function 'addd2sortedlist' for input arguments
of type 'double'.
}
a = add2sortedlist([1, 7, 10], 5);
1
7
10
Error in add2sortedlist (line 12)
counter=1;
{Output argument "ar" (and maybe others) not assigned
during call to
"/Users/mweeks/Documents/MATLAB/add2sortedlist.m>add2sortedlist".}
add2sortedlist
{Error using add2sortedlist (line 16)
Not enough input arguments.
}
add2sortedlist
{Error using add2sortedlist (line 16)
Not enough input arguments.
}
a = add2sortedlist([1, 7, 10], 5);
1
7
10
add2sortedlist
{Error using add2sortedlist (line 16)
Not enough input arguments.
}
a = add2sortedlist([1, 7, 10], 5);
ans =
1 is 1 value goes after
1
ans =
7 is 2 value goes after
7
ans =
10 is 3 value goes after
10
add2sortedlist
db quite
ans =
41.0616 41.3637 40.4238 41.2892 40.0864
quite
{Undefined function or variable 'quite'.
}
whos
Name Size Bytes Class Attributes
ans 1x5 40 double
dbquit
a = add2sortedlist([1, 7, 10], 5);
13 ar = [];
whos
Name Size Bytes Class Attributes
inputarray 1x3 24 double
inputnum 1x1 8 double
inputnum
inputnum =
5
dbquit
a = add2sortedlist([1, 7, 10], 5);
1
7
10
a = add2sortedlist([1, 7, 10], 5);
1 is 1 value goes after
7 is 2 value goes after
10 is 3 value goes after
a = add2sortedlist([1, 7, 10], 5);
1 is 1 value goes after
7 is 2 value goes after
10 is 3 value goes after
{Attempted to access inputarray(4); index out of bounds because
numel(inputarray)=3.
Error in add2sortedlist (line 21)
if (inputarray(counter) < inputnum)
}
type add2sortedlist.m
%
% add2sortedlist.m
%
% function to take a given array, and add a given number to it,
% in sorted order.
%
% a = add2sortedlist([1, 7, 10], 5);
% a would then become [1, 5, 7, 10]
%
%assuming array is sorted
function ar= add2sortedlist(inputarray, inputnum)
ar = [];
counter=1;
while(counter<= length(inputarray))
s = sprintf('%d is %d %s', inputarray(counter), counter, 'value goes after');
disp(s)
counter = counter + 1;
if (inputarray(counter) < inputnum)
disp ('after')
end
end
a = add2sortedlist([1, 7, 10], 5);
1 is 1 value goes after
7 is 2 value goes after
10 is 3 value goes after
{Attempted to access inputarray(4); index out of bounds because
numel(inputarray)=3.
Error in add2sortedlist (line 21)
if (inputarray(counter) < inputnum)
}
type add2sortedlist.m
%
% add2sortedlist.m
%
% function to take a given array, and add a given number to it,
% in sorted order.
%
% a = add2sortedlist([1, 7, 10], 5);
% a would then become [1, 5, 7, 10]
%
%assuming array is sorted
function ar= add2sortedlist(inputarray, inputnum)
ar = [];
counter=1;
while(counter<= length(inputarray))
s = sprintf('%d is %d %s', inputarray(counter), counter, 'value goes after');
disp(s)
if (inputarray(counter) < inputnum)
disp ('after')
end
counter = counter + 1;
end
a = add2sortedlist([1, 7, 10], 5);
1 is 1 value goes after
after
7 is 2 value goes after
10 is 3 value goes after
a = add2sortedlist([1, 2, 7, 10], 5);
1 is 1 value goes after
after
2 is 2 value goes after
after
7 is 3 value goes after
10 is 4 value goes after
a = add2sortedlist([1, 2, 7, 10], 5);
At index 1 is 1 after
At index 2 is 2 after
At index 3 is 7 after
At index 4 is 10 after
a = add2sortedlist([1, 2, 7, 10], 5);
At index 1 is 1 after
At index 2 is 2 after
At index 3 is 7 before
At index 4 is 10 before
[1, 2, 7, 10]
ans =
1 2 7 10
a = [1, 2, 7, 10]
a =
1 2 7 10
a(1:3)
ans =
1 2 7
a(2:4)
ans =
2 7 10
a(1:2)
ans =
1 2
a(3:4)
ans =
7 10
a(1:2), 5, a(3:4)
ans =
1 2
ans =
5
ans =
7 10
[a(1:2), 5, a(3:4)]
ans =
1 2 5 7 10
type add2sortedlist.m
%
% add2sortedlist.m
%
% function to take a given array, and add a given number to it,
% in sorted order.
%
% a = add2sortedlist([1, 7, 10], 5);
% a would then become [1, 5, 7, 10]
%
%assuming array is sorted
function ar= add2sortedlist(inputarray, inputnum)
ar = [];
counter=1;
while(counter<= length(inputarray))
if (inputarray(counter) < inputnum)
location = 'after';
else
n = counter;
location = 'before';
end
s = sprintf('At index %d is %d %s', counter,inputarray(counter), ...
location);
disp(s)
counter = counter + 1;
end
disp(n);
% ar = [inputarray(1:2), inputnum, inputarray(3:length(inputarray))];
a = add2sortedlist([1, 2, 7, 10], 5);
At index 1 is 1 after
At index 2 is 2 after
At index 3 is 7 before
At index 4 is 10 before
4
a = add2sortedlist([1, 2, 7, 10], 5);
At index 1 is 1 after
At index 2 is 2 after
At index 3 is 7 before
At index 4 is 10 before
2
type add2sortedlist.m
%
% add2sortedlist.m
%
% function to take a given array, and add a given number to it,
% in sorted order.
%
% a = add2sortedlist([1, 7, 10], 5);
% a would then become [1, 5, 7, 10]
%
%assuming array is sorted
function ar= add2sortedlist(inputarray, inputnum)
ar = [];
counter=1;
while(counter<= length(inputarray))
if (inputarray(counter) < inputnum)
location = 'after';
n = counter;
else
location = 'before';
end
s = sprintf('At index %d is %d %s', counter,inputarray(counter), ...
location);
disp(s)
counter = counter + 1;
end
% disp(n);
ar = [inputarray(1:n), inputnum, inputarray(n+1:length(inputarray))];
a = add2sortedlist([1, 2, 7, 10], 5);
At index 1 is 1 after
At index 2 is 2 after
At index 3 is 7 before
At index 4 is 10 before
sa
{Undefined function or variable 'sa'.
}
a
a =
1 2 5 7 10
b = add2sortedlist(a, 6)
At index 1 is 1 after
At index 2 is 2 after
At index 3 is 5 after
At index 4 is 7 before
At index 5 is 10 before
b =
1 2 5 6 7 10
diary off