undefined function or method of type char
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
the cyclist
am 29 Feb. 2012
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 Kommentare
the cyclist
am 29 Feb. 2012
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.)
Weitere Antworten (3)
Sean de Wolski
am 29 Feb. 2012
instead of 1,32 or 33,64, the comma (',') should be a colon (':');
doc colon
for more info
0 Kommentare
Walter Roberson
am 29 Feb. 2012
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 Kommentare
Walter Roberson
am 29 Feb. 2012
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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!