Printing Colon Values in a Vector

2 次查看(过去 30 天)
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 个评论
Fangjun Jiang
Fangjun Jiang 2011-10-20
Please ask one question at a time. After all, somebody else might search for a topic for answers.

请先登录,再进行评论。

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-10-20
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 个评论
Jake Bolanski
Jake Bolanski 2011-10-20
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axes Appearance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by