undefined function or method of type char
조회 수: 1 (최근 30일)
이전 댓글 표시
below is the link to my question. It is the first one listed on the homework in regards to image processing. Below it what I have started to but I keep getting an undefined function or method error of type char, any help or advice would be great!
funnyflag_2
for i = 1,32;
for j = 1,22;
r(i,j) = 1;
g(i,j) = 0;
b(i,j) = 0;
end
end
for i = 1,32;
for j = 23,46;
r(i,j) = 0;
g(i,j) = 1;
b(i,j) = 0;
end
end
for i = 1,32;
for j = 47,66;
r(i,j) = 0;
g(i,j) = 0;
b(i,j) = 0;
end
end
for i = 33,64;
for j = 1,22;
r(i,j) = 0;
g(i,j) = 1;
b(i,j) = 0;
end
end
for i = 33,64;
for j = 23,46;
r(i,j) = 0.5;
g(i,j) = 0.5;
b(i,j) = 0.5;
end
end
for i = 33,64;
for j = 47,66;
r(i,j) = 0;
g(i,j) = 0;
b(i,j) = 1;
end
end
r = c(:,:,1);
g = c(:,:,2);
b = c(:,:,3);
c = cat(3,r,g,b);
colormap(c);
image(myimage)
댓글 수: 0
채택된 답변
the cyclist
2012년 2월 29일
Is this the entire code? If so, then one problem is that when you get to this line:
r = c(:,:,1);
you have not yet defined the variable c, so MATLAB can't make the assignment.
댓글 수: 2
the cyclist
2012년 2월 29일
You don't need the colormap step. The image() function is going to take care of that for you. Leave that out.
Then, make the change that Sean and Walter mentioned, replacing all the for loops with code like i=1:32 rather than i=1,32.
If you do that, then your code is like this:
for i = 1:32;
for j = 1:22;
r(i,j) = 1;
g(i,j) = 0;
b(i,j) = 0;
end
end
for i = 1:32;
for j = 23:46;
r(i,j) = 0;
g(i,j) = 1;
b(i,j) = 0;
end
end
for i = 1:32;
for j = 47:66;
r(i,j) = 0;
g(i,j) = 0;
b(i,j) = 0;
end
end
for i = 33:64;
for j = 1:22;
r(i,j) = 0;
g(i,j) = 1;
b(i,j) = 0;
end
end
for i = 33:64;
for j = 23:46;
r(i,j) = 0.5;
g(i,j) = 0.5;
b(i,j) = 0.5;
end
end
for i = 33:64;
for j = 47:66;
r(i,j) = 0;
g(i,j) = 0;
b(i,j) = 1;
end
end
c = cat(3,r,g,b);
% r = c(:,:,1);
% g = c(:,:,2);
% b = c(:,:,3);
figure
image(c)
I think you will find that you are getting closer to what you meant to do. (But not quite there yet.)
추가 답변 (3개)
Sean de Wolski
2012년 2월 29일
instead of 1,32 or 33,64, the comma (',') should be a colon (':');
doc colon
for more info
댓글 수: 0
Walter Roberson
2012년 2월 29일
for i = 1,32;
is not the correct way to write a "for" loop over a range of values.
You do not indicate which line is complaining about undefined function or variable ?
댓글 수: 0
Walter Roberson
2012년 2월 29일
A colormap is not a 3D array: it is an N x 3 array, where N is the number of entries in the color map. For example, 256 x 3. The first column is red values, the second column is green values, the third column is blue values.
Remember, colormaps are row indexed by color numbers to determine the color to associate with a point for a pseudo-color plot. A pseudo-color plot has a single number for each point that is used for that row index, not a pair of numbers used for x-y indices.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!