How to define the specified vector [closed] - matlab

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed 3 years ago.
Improve this question
I want to define a vector y=[sin(1),sin(1/2),...,sin(1/1000)].
but I don't know how to do that. I defined
for i=1:1000
y(i)=sin(1/i);
end
but this does not work.

Just define the y as the following (and initialize to get the better performance):
y = zeros(1, 1000);
for i = 1:1000
y(i) = sin(1/i);
end
Also you can do it without for:
y = sin(1./(1:1000));

Related

For cycle setting from the n-1 position to the 1 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed 3 years ago.
Improve this question
I'm solving a specific matrix following a theoretical code from a book.
My issue is pretty simple I set that my last value from the one column matrix X is equal to the last one of my one column matrix Z.
After that I do for cycle where I need to pick the second to last until the first.
I don't know how to right this in code way
The book has " i = n-1,....,1 "
If it was i = 1, ....., n-1 it would be easy.
I tried the i=(n-1):1
And this i=(n-1):-1:1
Doesn't work. Returns has empty
To be clear to code is the follow:
i=n-1:1
x(i,1)=z(i,1)-u(i,i+1)*x(i+1,1)
So if n=4, i already have x(4).
So X(3)=z(3)-u(3,4)*x(4,1)
More of the code:
n=4;
Matrix=[2,-1,0,0,1;-1, 2,-1,0,0;0,-1,2,-1,0;0,0,-1,2,1];
u=eye(4,4);
l(1,1)=Matrix(1,1);
u(1,2)=Matrix(1,2)/l(1,1);
z(1,1)=Matrix(1,n+1)/l(1,1);
for i=2:n-1
l(i,i-1)=Matrix(i,i-1);
l(i,i)=Matrix(i,i)-l(i,i-1)*u(i-1,i);
u(i,i+1)=Matrix(i,i+1)/l(i,i);
z(i,1)=(Matrix(i,n+1)-l(i,i-1)*z(i-1,1))/l(i,i);
endfor
l(n,n-1)=Matrix(n,n-1);
l(n,n)=Matrix(n,n)-l(n,n-1)*u(n-1,n)
z(n,1)=(Matrix(n,n+1)-l(n,n-1)*z(n-1,1))/l(n,n)
x(n,1)=z(n,1);
for i=(1-n):-1:1
x(i,1)=z(i,1)-u(i,i+1)*x(i+1,1);
endfor

Why is my for loop running over? (Matlab) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed 6 years ago.
Improve this question
I have the following code:
for i = 1:RGB_size(2) % RGB_size(2) = 1296 //X coords
for j = 1:1:RGB_size(1) % RGB_size(1) = 964 //Y coords
if mask(i,j) == 1
data(next_pixel,:) = [ImgIndex, ImgTake, i, j, RGB(i,j,1), RGB(i,j,2), RGB(i,j,3),...
HSIR(i,j,1), HSIR(i,j,2), HSIR(i,j,3)];
next_pixel = next_pixel + 1; %get next pixel
end
end
end
But Matlab won't run my code because it says I'm trying to access mask(965,1) and my variable mask size is 1296×964. However, I don't see how this is possible. Any thoughts?
RGB_size is calculated from a variable called RGB, which is the same variable used to create the variable mask. I have verified that they are both the same size with the debugger.
Actual error message is:
Attempted to access mask(965,1); index out of bounds because size(mask)=[964,1296].
You have switched the i and j index of the mask.

why I can't use function readframe in matlab [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
I write this code but have error "Undefined function 'readframe' for input arguments of type 'VideoReader'"
How to I will solve? thank you.
v = VideoReader('filename.avi');
video = readframe(v,1);
figVid = figure();
axeVid = axes('Parent', figVid);
image(video, 'Parent', axeVid);
Actual Answer: The function is readFrame() not readframe().

How to read frames from a video MATLAB? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
I have to read video frames one by one from image and store each frame in an array which I can further use. I guess there must be some loop which can do this work.
I am using:
video=VideoReader('sample.avi')
frm = read(video) % to get frame
but MATLAB gives error on read command and close automatically as shown in the attached image:
.
Can anyone help me please?
From the documentation:
v = VideoReader('xylophone.mp4');
while hasFrame(v)
video = readFrame(v);
end
or from the documentation of VideoReader.read
video = read(v,[1 Inf]);

Distance measurement in Matlab [closed]

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.