warning: implicit conversion from matrix to string

Thomas Weber thomas.weber.mail at gmail.com
Wed Sep 3 01:40:48 CDT 2008


Am Dienstag, den 02.09.2008, 20:31 -0400 schrieb Vic Norton:
> How do I get rid of implicit conversion warnings when printing an  
> array of strings of the same length? For example the script
> 
> 	% test2.m
> 
> 	global SEC_PER_HOUR = 3600;
> 	SEC_PER_DAY = 24 * SEC_PER_HOUR;
> 	SEC_PER_WEEK = 7 * SEC_PER_DAY;
> 	
> 	function  date = time2dateEST( time )
> 	## The date returned is the "%Y-%m-%d"-formatted EST date
> 	## corresponding to time.
> 		global SEC_PER_HOUR;
> 		time -= 5 * SEC_PER_HOUR;
> 		date = strftime("%Y-%m-%d", gmtime( time ) );
> 	endfunction
> 	
> 	dates = zeros(5, 10);
> 	time = 1082667600;
> 	for i = 1 : 5
> 	   dates(i, :) = time2dateEST(time);
> 	   time += SEC_PER_WEEK;
> 	endfor
> 	
> 	for i = 1 : 5
> 	   printf("%s\n", dates(i, :));
> 	endfor
> 
> produces
> 
> 	octave-3.0.2> test2
> 	warning: implicit conversion from matrix to string
> 	2004-04-22
> 	warning: implicit conversion from matrix to string
> 	2004-04-29
> 	warning: implicit conversion from matrix to string
> 	2004-05-06
> 	warning: implicit conversion from matrix to string
> 	2004-05-13
> 	warning: implicit conversion from matrix to string
> 	2004-05-20
> 
> on my system.
> 
> Obviously the dates have been "converted" correctly. What is the  
> problem here?

I'm actually surprised that your strings are correctly converted. I
would use a cell instead of the matrix:

dates = cell(1, 5);
time = 1082667600;
for i = 1 : 5
  dates(i) = time2dateEST(time);
  time += SEC_PER_WEEK;
endfor
 
for i = 1 : 5
  printf("%s\n", dates(i));
endfor

	Thomas



More information about the Help-octave mailing list