🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.soft-sys.matlab
6 messages
6 total messages Started by Michael Maurer Sat, 23 Jan 1993 01:04
SOURCE: mat2str.m - convert matrix to string format
#18
Author: Michael Maurer
Date: Sat, 23 Jan 1993 01:04
52 lines
1974 bytes
Hoping to start a trend, here is an unsolicited matlab m-file.
MAT2STR is like NUM2STR, but operates on matrix input.
Suggested improvements are welcome.

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	mat2str.m
# This archive created: Fri Jan 22 16:55:43 1993
export PATH; PATH=/bin:$PATH
echo shar: extracting "'mat2str.m'" '(468 characters)'
if test -f 'mat2str.m'
then
	echo shar: will not over-write existing file "'mat2str.m'"
else
sed 's/^XX//' << \SHAR_EOF > 'mat2str.m'
XXfunction T=mat2str(X,nc,nd)
XX
XX%MAT2STR
XX%	T=mat2str(X) converts matrix X into string format T, using sprintf
XX%	to convert each element of X.
XX%	T=mat2str(X,nc) uses nc characters for each column, instead of
XX%	default 12.
XX
XX%	Michael Maurer, 10 Jan 1992
XX%	Copyright (c) 1993 by Michael Maurer
XX
XXif nargin<2,
XX   nc=12;
XXend
XX
XX[mx,nx]=size(X);
XXT=ones(mx,nc*nx)*abs(' ');
XXfor i=1:mx,
XX   for j=1:nx,
XX      t=sprintf('%.4g',X(i,j));
XX      T(i,nc*(j-1)+(1:length(t)))=t;
XX   end
XXend
SHAR_EOF
if test 468 -ne "`wc -c < 'mat2str.m'`"
then
	echo shar: error transmitting "'mat2str.m'" '(should have been 468 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
--
______________________________________________________________________
Michael Maurer          maurer@nova.stanford.edu        (415) 723-1024
Re: SOURCE: mat2str.m - convert matrix to string format
#23
Author: Brian Fitzgerald
Date: Sat, 23 Jan 1993 13:12
10 lines
717 bytes
Michael Maurer <maurer@nova.stanford.edu> writes:
>Hoping to start a trend, here is an unsolicited matlab m-file.

Good trend.  We need a comp.sources.matlab newsgroup.

  -- moderated or not moderated ?

Also, it would be nice if it could be archived somewhere.

Brian
Re: SOURCE: mat2str.m - convert matrix to string format
#27
Author: V. Phaniraj
Date: Sat, 23 Jan 1993 22:54
12 lines
1235 bytes
In article <=vl3m8d@rpi.edu>, fitzgb@mml0.meche.rpi.edu (Brian Fitzgerald) writes...
>Michael Maurer <maurer@nova.stanford.edu> writes:
>>Hoping to start a trend, here is an unsolicited matlab m-file.

>Also, it would be nice if it could be archived somewhere.

The Matlab User Group files are archived at research.att.com,
in /netlib/matlab ( I think). There are several megabytes worth of .m
files stored there, and I have found several very useful programs there.

V. Phaniraj          phaniraj@plains.nodak.edu
EE, North Dakota State University
Re: SOURCE: mat2str.m - convert matrix to string format
#61
Author: ellert
Date: Mon, 25 Jan 1993 22:06
31 lines
1559 bytes
In article <maurer.727751047@nova.Stanford.EDU>, Michael Maurer <maurer@nova.stanford.edu> writes:
>
>Hoping to start a trend, here is an unsolicited matlab m-file.
>MAT2STR is like NUM2STR, but operates on matrix input.
>Suggested improvements are welcome.

Okay, here's an improvement, at least it should be since 1) it doesn't use
for loops in matlab, and 2) has far fewer function calls.  But I didn't
benchmark it.  Whenever I see those for loops I like to find ways to get
rid of them with matrix operations.

function T=mat2str(X,nc)
%MAT2STR
%     T=mat2str(X) converts matrix X into string format T, using sprintf
%     to convert each element of X.
%     T=mat2str(X,nc) uses nc characters for each column, instead of
%     default 12.

%     originally by Michael Maurer, 10 Jan 1992
%     modified by Ed Ellert, 25 Jan, 1993

if nargin<2,
   nc=12;
end

[mx,nx]=size(X);
T = reshape([setstr(X+'0'); ' '*ones((nc-1)*mx, nx)], mx, nx*nc);

Ed Ellert
ellert@nu1.uh.cwru.edu
Re: SOURCE: mat2str.m - convert matrix to string format
#74
Author: ellert
Date: Tue, 26 Jan 1993 14:16
36 lines
1731 bytes
I wrote:
>
>In article <maurer.727751047@nova.Stanford.EDU>, Michael Maurer <maurer@nova.stanford.edu> writes:
>>
>>Hoping to start a trend, here is an unsolicited matlab m-file.
>>MAT2STR is like NUM2STR, but operates on matrix input.
>>Suggested improvements are welcome.
>
>Okay, here's an improvement, at least it should be since 1) it doesn't use
>for loops in matlab, and 2) has far fewer function calls.  But I didn't
>benchmark it.  Whenever I see those for loops I like to find ways to get
>rid of them with matrix operations.
>
>function T=mat2str(X,nc)
>%MAT2STR
>%     T=mat2str(X) converts matrix X into string format T, using sprintf
>%     to convert each element of X.
>%     T=mat2str(X,nc) uses nc characters for each column, instead of
>%     default 12.
>
>%     originally by Michael Maurer, 10 Jan 1992
>%     modified by Ed Ellert, 25 Jan, 1993
>
>if nargin<2,
>   nc=12;
>end
>
>[mx,nx]=size(X);
>T = reshape([setstr(X+'0'); ' '*ones((nc-1)*mx, nx)], mx, nx*nc);

Oops!  Walking to work this morning it occurred to me that this will only
work for single digits.  It was fun though :^)

Ed Ellert
ellert@nu1.uh.cwru.edu
Re: SOURCE: mat2str.m - convert matrix to string format
#132
Author: Andrew Knight
Date: Thu, 28 Jan 1993 14:28
43 lines
1723 bytes
Seems to be a bug here. Here's what I got out of Michael's original 
version:
>> x=rand(3,3) 
 
x =

    0.3653    0.7227    0.0727
    0.2470    0.7534    0.6316
    0.9826    0.6515    0.8847

>> mat2str(x,9)

ans =

0.3653   0.7227   0.07269  
0.247    0.7534   0.6316   
0.9826   0.6515   0.8847 

Seems fine.  Here's what Ed's one gave:
>> mat2str(x,9)

ans =
 
0        0        0        
0        0        0        
0        0        0        


A bit inaccurate?

Andrew Knight                                
Maritime Operations Division		     
Defence Science and Technology Organisation  
PO Box 1750
Salisbury, SA 5108
Australia
----------------------------------------------------------------------------
            ,-_|\                                e-mail: ajk@mod.dsto.gov.au
  DSTO     /     \                                phone:       61 8 259 5487
AUSTRALIA  \_,-*_/                                  fax:       61 8 259 5139
	        v                            
----------------------------------------------------------------------------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads