rand()
function return value?a = rand(1, 11);
b = sort(a);
c = b(1, ceil(end/2));
while
loop?a = 0;
do
a = a + 1;
while a < 5
end
a = 0;
while(a < 5)
a = a + 1;
a = 0;
while a < 5:
a = a + 1;
a = 0;
while a < 5
a = a + 1;
end
b
contain?a =
19 20 12 0 6
6 9 56 0 3
46 8 9 8 19
9 8 8 19 46
1 9 46 6 19
b =
56 0
9 8
b =
8 19
19 46
myfun
and want to measure how long it takes to run. Which code segment will return in t
the time in seconds it takes myfun
to run?t = cputime(myfun());
tic;
myfun();
toc;
timer.start;
myfun()
t = timer.stop;
t = timer(myfun());
%%
used for?.
character NOT used for?mean
, median
, and mode
return the same value?x = [-1:0.1:1];
y = X.^2;
plot(x, y)
figure
was not called immediately in advance. plot
syntax is incorrect. name
in structure S?a = [1 2 3; 4 5 6];
b = zeros(size(a));
for i_row = 1:size(a, 1)
for i_col = 1:size(a, 2)
b(i_row, i_col) = a(i_row, i_col)^2;
end
end
c
?a = ones(1,3);
b = 1:3;
c = conv(a,b)
switch
statement?x = 7;
switch x
case 2
disp("two");
otherwise
disp("not two");
end
x = 7;
switch x :
case 2
disp("two");
otherwise
disp("not two");
end
x = 7;
switch x
case 2
disp("two");
else
disp("not two");
end
x = 7;
switch x
case 2
disp("two");
default
disp("not two");
end
a = 1;
b = 2;
c = 3;
d = 4;
e = c / (~a - b == c - d);
c =
NaN
c =
Inf
c =
-0.2500
eq
function. f10
than the other three?f10 = 1;
for i = 1:10
f10 = f10 * i;
end
f10 = factorial(10)
f10 = 1;
i = 1;
while i <= 10
i = i + 1;
f10 = i * f10;
end
f10 = prod(1:10)
a = rand(5);
round(a * inv(a))
diag(ones(5, 1))
identity(5)
eye(5)
dog =
name: 'Bindy'
breed: 'border collie'
weight: 32
dog = struct('name', 'Bindy'; 'breed', 'border collie'; 'weight', 32);
dog.name = 'Bindy';
dog.breed = 'border collie';
dog.weight = 32;
dog = {
'name' : 'Bindy',
'breed' : 'border collie',
'weight': 32;
}
dog('name') = 'Bindy';
dog('breed') = 'border collie';
dog('weight') = 32;
my_func
is a function as follows. What is the value of a
at the end of the code beneath?function a = my_func(a)
a = a + 1;
end
------------------
a = 0;
for i = 1:3
my_func(a);
end
a = my_func(a);
c = {["hello world"]} {1×1 cell} {["goodbye"]} {1×3 double}
{"hello world" {"hello"} "goodbye" [1 2 ]};
{"hello world" {"hello"} "goodbye" {[1 2 3]}};
{"hello world" {"hello"} "goodbye" [1 2 3]};
{"hello world" {"hello" "hello"} "goodbye" {[1 2 3]}};
b
to each row of a
?a = ones(4, 4);
b= [1 2 3 4];
a
s with o
s?for i = 1:length(fruit)
fruit{i}(fruit{i} == a) == o;
end
for i = 1:length(fruit)
fruit(i)(fruit(i) == 'a') == 'o';
end
for i = 1:length(fruit)
fruit{i}(fruit{i} == 'a') == 'o';
end
for i = 1:length(fruit)
fruit{i}(fruit{i} == 'a') == 'o';
x^2 + 2x - 4
?a
to the end of 1x 2 dimensional cell array C
?height
. Which statement will return a 100 x 1 array, sim_height
, with values from a normal distribution with the same mean and variance as your height data?burger
' from menu
?menu = {'hot dog' 'corn dog' 'regular burger' 'cheeseburger' 'veggie burger'}
a
may contain?a = randi(10, [1, 10]);
a(3) = 11;
a(a>2) = 12;
sparse
function to remove empty cells from cell array variables. sparse
function requires its input to be a full matrix with at least 50% zero elements. a = 1:10;
menu
into the variable menu_string
below?menu = {'hot dog' 'corn dog' 'regular burger' 'cheeseburger' 'veggie burger'}
menu_string =
'hot dog
corn dog
regular burger
cheeseburger
veggie burger'
rng_settings_curr = rng('shuffle');
rng(time());
rng_settings_curr = rng();
rng_settings_curr = rand('shuffle');
rng('shuffle');
rng_settings_curr = rng();
data
in which each column is mono audio recording from a room in your house. You've noticed that each column has a very different mean and when you plot them all on the same graph, the spread across the y axis make it impossible to see anything. You want to subtract the mean from each column. Which code block will accomplish this?data_nomean = data - repmat(median(data), size(data, 1), 1);
data_nomean = bsxfun(@minus, data, mean(data));
data_nomean = zeros(size(data));
for i = 1:size(data, 1)
data_nomean(i, :) = data(i, :) - mean(data(i, :));
end
data_nomean = zscore(data');
b
containing the mean values of each array within C
?b = zeros(1, size(C, 2));
for i_C = 1:size(C, 2)
b(i_C) = mean(C(i_C));
end
b = cellfun(@mean, C);
b = zeros(1, size(C, 1));
for i_C = 1:size(C, 1)
b(i_C) = mean(C{i_C}(:));
end
b = cellfun(@(m) mean(m(:)), C)
passwords
contains a digit and 0 if it does not?passwords = {'abcd' '1234' 'qwerty' 'love1'};
figure
x = rand(10,10);
r = corrcoef(x);
surf(r)
colorbar
figure
x = rand(10,10);
r = corrcoef(x);
imagesc(r)
colorbar
a = 1:10;
b = a(randi(10, 1, 10));
m = perms(a);
i = randi(factorial(10), 1);
b = a(m(i, :))
[s, j] = sort(rand(10, 1));
b = a(i);
b = a(randperm(10));
a = 'stand'
b = "stand"
C = {'dog' 'cat' 'mouse'}
D = {'cow' 'piranha' 'mouse'}
E = setdiff(C,D)
x = 9.0646 6.4362 7.8266 8.3945 5.6135 4.8186 2.8862 10.9311 1.1908 3.2586
y = 15.4357 11.0923 14.1417 14.9506 8.7687 8.0416 5.1662 20.5005 1.0978
coeff_line = polyfit(x,y,1)
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line)
figure; plot(x,y,'o')
hold on
plot(x_linemy_line)
figure
plot(x,y,'o')
coeff_line = polyfit(x,y,1);
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line);
plot(x_line,y_line)
figure
plot(x,y)
coeff_line = polyfit(x,y,1);
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line);
hold on; plot(x_line,y_line)
coeff_line = polyfit(x,y,1);
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line);
figure; plot(x,y,'o')
hold on
plot(x_line,y_line)
a = [0 1 2 3; 4 5 6 7];
a = a^2;
___
.function mystery_func(a) :
return a
function b = mystery_func(a)
b = a;
end
def b = mystery_func(a)
b = a;
end
function mystery_func(a)
b = a;
return b;
end
a = [1 2; 3 4];
b = a(:,2);
c = b + 3;
a(1:2,1) = c;
a =
6 3
7 4
a =
5 2
7 4
a =
5
7
a =
6
7
h_f = figure; set(h_f,'Color', [0 0 0]);
h_a = gca; set(h_a,'Color', [0 0 0]);
h_a = axes; set(h_a,'Color', [0 0 0]);
h_f = gcf; set(h_a,'Color', [0 0 0]);
2*[1:5]+1
1:2:9
isodd(1:9)
1:odd:9
imfilter
command performs a convolution operation between an image and a matrix. Suppose you have an image loaded in MATLAB into the variable img
and you apply the following code. The original image appears slightly blurred because the convolution smoothed out the image (removed noise). Why do you think this happened?h = ones(5,5)/25;
imshow(imfilter(img,h));
h
is a Gaussian filter that adds to 1. Its intended effect is to highlight image edges. h
is an averaging filter uniformly distributed that adds to 1. Its intended effect is to smooth out images (remove noise). h
is a Laplacian filter that adds up to 0. Its intended effect is to smooth out images (remove noise). imfilter
is a function that always blurs the images. b
?a = [1 2 3];
b = repmat(a,2,3);
a
?a = [ 1 2 3 4];
c = [7,8,9]
c = [7: 8: 9]
c = [7; 8; 9]
c = [7 8 9]
who
vars
whos
who all
snap
in an m-file and when you call it, you're not getting the output you expect. You previously wrote a different function named snap
, which you think might also be on the search path. Which command can you use to see if the old snap
function is being called?-v7.3
flag?a = randn(1,1000); histogram(a) ylabel('counts')
a = rand(1,1000); histogram(a) ylabel('counts')
a = randi(1,1000); histogram(a) ylabel('counts')
a = rng(1,1000); histogram(a) ylabel('counts')
s="abcd"; s(3)='x'
c = [9 8 0];
d = [0 0 1];
e = union(c,d);
e = [0 0 1 9 8 0]
e = [9 8 0 0 0 1]
e = [0 1 8 9]
e = [1 8 9]
a = 1;
for i_loop = 1:6
disp(a);
end
111111
1 1 1 1 1 1
1
1
1
1
1
1
nothing will print
b = ['stand' 'alone'];
c = {rand(20,10) rand(23,2) rand(14,5)}
b = cellfun(@(m) mean(m(:)), C
b = zeros(1, size(C,1);
for i_C = 1:size(C,1)
b(1_C) = mean(C{i_C}(:));
end
b = cellfun(@mean, C)
b = zeros(1, size(C,2);
for i_C = 1:size(C,2)
b(1_C) = mean(C(i_C));
end
if else
statement?if (a > 1):
b = 2;
else:
b = 3;
if (a > 1){
b = 2;
} else{
b = 3;
}
if (a > 1)
b = 2;
else
b = 3;
end
if (a > 1)
b = 2;
else
b = 3;
a = [9 8 8 19 6 1 9 6 6 19];
b = unique(a);
b = [1 6 8 9 19]
b = [1 6 8 9]
b = [1 6 6 6 8 8 9 9 19 19]
b = [1 6 6 8 8 9]