Printing Colon Values in a Vector

3 views (last 30 days)
Hello,
I am having a little trouble printing out colon values in a vector. For example:
for x = 1:10
y(x) = x
end
This seems to work for me. However, what if the values for x do not start with 1?
For example what I have right now is this:
for x= 23:78
y(x) = x
end
This produces a result like [0 0 0 ... 23 24 25 ... 78]. What I want to be able to do is start with 23 and end at 78 without the 0's; hence: [23 24 25 ... 77 78]. Any advice?
Thanks.
Also,
I am having a little trouble obtaining the mean values for y_coordinates in a rectangle. Currently, I am able to plot a rectangle about the centroid of a flower. What I want to do is use the impixel() command to obtain the RGB values - such that I can know the color. Since the x_values in the rectangle are same as the y_values change, mean(x_cood:x_cood + width) seems to work for me. However, I am unable to present the same for the y_cood. In other words, I want to be able to take the mean of all the y_coordindates at the x_coordinates such that I have an average of all the values within the rectangle. Then, I want to run the impixel() command. Here is what I have:
for U = 1:5:height
% plot(x_cood:x_cood + width,y_cood + U,...
% '--rs','LineWidth',2,...
% 'MarkerEdgeColor','k',...
% 'MarkerFaceColor','r',...
% 'MarkerSize',2)
% hold on;
x_mean = mean(x_cood:x_cood + width);
y_mean = mean(y_cood + U);
plot(x_mean,y_mean,...
'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','r',...
'MarkerSize',2)
hold on;
rect_pixel = impixel(cam_image_rgb,x_mean,y_mean);
r = rect_pixel(1);
g = rect_pixel(2);
b = rect_pixel(3);
fprintf('Red = %0.2f, Green = %0.2f, Blue = %0.2f\n',r,g,b)
end
  1 Comment
Fangjun Jiang
Fangjun Jiang on 20 Oct 2011
Please ask one question at a time. After all, somebody else might search for a topic for answers.

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 20 Oct 2011
It is a matter of an offset, right?
Original:
for x= 23:78
y(x) = x
end
Can be done as:
for x= 23:78
y(x-22) = x
end
Or: y=23:78
  1 Comment
Jake Bolanski
Jake Bolanski on 20 Oct 2011
Thanks! On a separate note, do you know if it is possible for me to tell the color using RGB values in MatLab? Currently I have r = 243, g = 246, b = 77. Is it possible to say this falls in the yellow category?

Sign in to comment.

More Answers (0)

Categories

Find more on Axes Appearance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!