Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Help with a matrix with words
Replies: 1   Last Post: May 18, 2013 5:07 PM

 Messages: [ Previous | Next ]
 ferne17 Posts: 1 Registered: 5/18/13
Help with a matrix with words
Posted: May 18, 2013 2:52 PM

Hello, I need help with my code because I'm trying to do a Island to work with cellular automaton and in the middle of the Island I need numbers, but I want that the Island have a Sea so in the edge I need the letter "M"! to identificate the Sea. Here is my code but Matlab send me an error, I hope someone can help me:
clc;
clear;
len=7;
GRID=zeros(len+2,len+2); %Matriz inicial de len+2 x len+2
for i=3:len
for j=3:len
GRID(i,j)=floor(3.99*rand); %matriz se rellena desde la (3,3) hasta (len,len)
end %
end %
for j=2:2:len+1 % el for es con len+1 y no len+2, porque sino
GRID(2,j)=1; % me rellenarĂ¡ la ultima columna qe es mar
end % y parte desde la segunda columna x el mar
for i=2:2:len+1
GRID(i,2)=1;
end
for j=2:2:len+1 % el for es con len+1 y no len+2, porque sino
GRID(len+1,j)=1; % me rellenarĂ¡ la ultima columna qe es mar
end
for i=2:2:len+1
GRID(i,len+1)=1;
end
%AHORA EL MAR
for j=1:len+2
GRID(1,j)={'M'};
end
for i=1:len+2
GRID(i,1)='M';
end
for j=1:len+2
GRID(len+2,j)='M';
end
for i=1:len+2
GRID(i,len+2)='M';
end
GRID

The following error occurred converting from cell to double:
Error using double
Conversion to double from cell is not possible.

Error in Prueba2 (line 24)
GRID(1,j)={'M'};

Greetings

Date Subject Author
5/18/13 ferne17
5/18/13 Derek Goring