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)

采纳的回答

the cyclist
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 个评论
Matthew
Matthew 2012-2-29
This is the entire code, i ordered the last few lines so c is defined and changed the image line so it reads
c = cat(3,r,g,b);
r = c(:,:,1);
g = c(:,:,2);
b = c(:,:,3);
colormap(c);
image(c)
but i am getting a colormap error now, and it says that color map must have three columns [R G B]
I guess what im trying to do is define a vector of nxm and allocate specific colors intro a matrix to get the image posted in the link. Im really confused what else I should tweak?
the cyclist
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
Sean de Wolski 2012-2-29
instead of 1,32 or 33,64, the comma (',') should be a colon (':');
doc colon
for more info

Walter Roberson
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 ?

Walter Roberson
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.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by