Printing Colon Values in a Vector

조회 수: 2 (최근 30일)
Jake Bolanski
Jake Bolanski 2011년 10월 20일
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