Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have written the following MATLAB code and as I initialized the matrix stab1, I think this matrix should have 4991 elements at the end, but when I run the code, stab1 has 801445 elements at the end. Is the problem with my code?
stab1=zeros(1,4991);
k=0;
for ii=-0.6:0.01:-.3
m=0;
for jj=0:0.01:1.6
m=m+1;
if .... (some condition)
stab1(k*161+m)=1;
end
k=k+1;
end
end
You have put the k=k+1 at a wrong place. It is the correct code:
stab1=zeros(1,4991);
k=0;
for ii=-0.6:0.01:-.3
m=0;
for jj=0:0.01:1.6
m=m+1;
if .... (some condition)
stab1(k*161+m)=1;
end
end
k=k+1;
end
Now it has 4991 elements.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
For matalb there's an error at line 9, where I define dy(1), but it doesn't say what kind of error.
function dy=pred_prey(t,y)
k=1;
a=2/3;
d=4/3;
f=#(x)cos(x.^2)
r=#(t)integral(f,0,t);
mu=#(t)13/20-(3/5)*exp(-(3/t));
dy(1)=(y(1)+k)*r-a*y(1)*y(2);
dy(2)=-mu*y(2)+d*y(1)*y(2);
dy=dy';
You define r as an anonymous function, but you don't pass any arguments to it when you call it on line 9. The line should be (I assume):
dy(1) = (y(1)+k)*r(t)-a*y(1)*y(2);
Incidentally, you're going to have the same problem on the next line where you call mu with no arguments as well.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
i keep getting the error "Error using -""Matrix dimensions must agree"
for this piece of code. Can anybody help me and identify where i'm going wrong? I should be getting 8 plots of f vs d.
P=500;
N=1:1:8;
a=-0.4;
b=-1;
Kd=700;
d50star=(1./(10.^(Kd*(N.^a)*(P-115).^b)))
w0=0.45;
d=0:0.1:10
d50N0=5;
if d50star < 0.33;
w=(1-(2.3*d50star))*w0
else
w=(3.4-(5.5*d50star))*w0
end
d50=(1-d50star)*d50N0;
f=1-(1./((1+exp((d-d50)/w))))
There are at least two errors in the script:
1) in the last line [f=1-(1./((1+exp((d-d50)/w))))]
d size is 1x101
d50 size is 1x8
The size inconsistency is related to the definition of:
N=1:1:8; and
d=0:0.1:10
2) depending on the algoroth, it could be ./w instead of /w
Hope this helps.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have tried the code from the link Ear Image Processing - Finding the point of intersection of line and curve in MATLAB
but seem to get an error as dist2s is undefined on matlab R2013a.Can anyone help me out
That's because you need to create the function (isn't defined by MatLab itself). Try saving this code in a file called dist2s.m and then setting the folder where it's located like current folder:
function out = dist2s(pt1,pt2)
out = NaN(size(pt1,1),size(pt2,1));
for m = 1:size(pt1,1)
for n = 1:size(pt2,1)
if(m~=n)
out(m,n) = sqrt( (pt1(m,1)-pt2(n,1)).^2 + (pt1(m,2)-pt2(n,2)).^2 );
end
end
end
return;
The code is provided in the same answer you refer to.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
function y = CramersRule(A,b)
[m,n] = size(A);
[o,p] = size(b);
if m~=2 | n~=2 | o~=2 | p~=1
error('the matrices must be 2*2 and 2*1')
A=[a b;c d]
b=[e;f]
X = det([e b;f a])/det([a b;c d])
Y = det([a e;c f])/det([a b;c d])
end
end
I just get the result: CramersRule([1 2;3 4], [0;4]), which was an example I used to test it.
There are several strange things here:
First of all you have an if statement that contains an error, but even though there is an error you still do things inside the same statement, perhaps you wanted an else somewhere?
Secondly you use A=[a b;c d] while a, c and d are not even defined.
Thirdly you assign to X and Y which are never even used.
Lastly you ask y as an output argument, whilst there is never an assignment to this. Perhaps you don't realize that matlab is case sensative?
All in all it is just a strange function now. Don't forget to check the mlint (warnings on the right hand side of your screen) as it can pick up most of these things.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to apply sliding window for subtracting two different images in matlab,
the window size must be 4X4,
please help me
i want to find similarity value between two different images.if A and B are two 2 images take difference between each 4x4 matrix of each A&B in sliding window manner
i tried a code ,i dont know whether it is correct or not
m=imread('index.jpeg');
sal=imread('salt.jpg');
salt=rgb2gray(sal);
ab=rgb2gray(m);
imshow(ab);
imh=size(ab,2);
imw=size(ab,1);
wh=4;
ww=4;
k=0;
disp(imh),disp(imw);
if 1
for j=1:imh+wh-1
for i=1:imw+ww-1
w1=ab(j:j+wh-1,i:i+wh-1,:);
w2=salt(j:j+wh-1,i:i+wh-1,:);
w3=w1-w2;
disp(w3);
disp('next mat');
end
k=k+1;
disp(k);
end
end
The upper bounds of your for-loops are the cause for your troubles.
You specify:
imh=size(ab,2);
imw=size(ab,1);
However, your for-loops have these conditions:
j=1:imh+wh-1
and
i=1:imw+ww-1
So you move past both the 'height' and the 'width' dimension.
Try this instead:
for j=1:imh-wh
for i=1:imw-ww
w1=ab(j:j+wh,i:i+wh,:);
w2=salt(j:j+wh,i:i+wh,:);
w3=w1-w2;
end
k=k+1;
end