error using std (used to work and works on other people's computer)

5 views (last 30 days)
Hi, I'm trying to applicate BTC coding to a matrix and I get an error using std even though my matrix is composed of doubles
My friend sent me his working program but it does not work on my computer.
PS: I'm pretty sure my program used to work just fine when I first programmed it
function [mo,so,mf,sf,bRecons] = btcBlock(b0rigin)
bRecons = double(b0rigin);
mo = mean(bRecons(:),1);
so = std(bRecons(:),1);
q=0;
for l = 1 : 1 : size(bRecons,1)
for c = 1 : 1 : size(bRecons,2)
if bRecons(l,c) < mo
bRecons(l,c) = 0;
else
bRecons(l,c) = 1;
q = q + 1;
end
end
end
m = size(b0rigin,1) * size(b0rigin,1);
inf = mo - so*sqrt((q)/(m-q));
supp = mo + so*sqrt((m-q)/(q));
inf = floor(inf);
supp = floor(supp);
for l = 1 : 1 : size(bRecons,1)
for c = 1 : 1 : size(bRecons,2)
if bRecons(l,c) == 0
bRecons(l,c) = inf;
else
bRecons(l,c) = supp;
end
end
end
mf = mean(bRecons(:),1);
sf = std(bRecons(:),1);
end
here is what I type
A =
[245 239 249 239
245 245 239 235
245 245 245 245
245 235 235 239]
btcBlock(A)
Here is what I get
Error using var
Too many input arguments.
Error in std (line 59)
y = sqrt(var(varargin{:}));
Error in btcBlock (line 4)
so = std(bRecons(:),1);
Thank you in advance
  1 Comment
Star Strider
Star Strider on 13 Dec 2020
bastien alves posted as an Answer:
I forgot to put my friend's code, that does the same thing, works on his computer, but not mine
function btcBlock
N = 4;
bOrigin = [245 239 249 239;
245 245 239 235;
245 245 245 245;
245 235 235 239];
bRecons = zeros(4);
m = mean(mean(bOrigin));
s = std(bOrigin(:) ,1);
q = 0;
for i= 1:N
for j = 1:N
if (bOrigin(i , j) > m)
bRecons(i, j) = 1;
q = q + 1;
else
bRecons(i, j) = 0;
end
end
end
a = floor(m - s * sqrt(q / (N^2 - q)));
b = floor(m + s * sqrt((N^2 - q) / q));
for i= 1:N
for j = 1:N
if (bRecons(i , j) == 0)
bRecons(i, j) = a;
else
bRecons(i, j) = b;
end
end
end
mRecons = mean(mean(bRecons));
sRecons = std(bRecons(:) ,1);
a
b
bRecons
m
s
mRecons
sRecons
end

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 13 Dec 2020
My guess is that you have variables named ‘std’ and ‘var’.
Check that by running these in a script of your Command Window:
which std -all
which var -all
If the first entry in the result is:
std is a variable.
and similarly for ‘var’, you have likely found the problem. The solution is to rename the variables.
  15 Comments
bastien alves
bastien alves on 14 Dec 2020
okay I did not know that, but I still get the same error after removing the file from the path
Star Strider
Star Strider on 14 Dec 2020
The file may still be hiding somewhere. The definitive fix is to rename the function itself, and all references to it in the project code you were given.
I echo Image Analyst’s last two-sentence paragraph! Why would your university give you code with a function that overshadows the MATLAB var funciton? You and your fellow students need to bring that up to whomever is responsible for it.

Sign in to comment.

Tags

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!