[scilab-Users] mfprintf
Adrien Vogt-Schilb
vogt at centre-cired.fr
Wed Jul 20 15:03:27 CEST 2011
On 20/07/2011 14:59, Adrien Vogt-Schilb wrote:
> On 20/07/2011 14:25, computidoo wrote:
>> hello,
>>
>> and i want to have in the ascii
>> a
>> ======
>> 1 1
>> 1 1
>> ======
>>
>> what is the line that i have to write
>>
>> best regard
>> computidoo
>
> Hi
the precedent mail was poorly rendered, here it goes again without fancy
formating :
//I would recommend to drop the "===", so the file is much easier to parse
function mybetterexport(varname)
matval = evstr(varname);
[n m] = size(matval);
output = emptystr(n+1,m); //n+3 if you
// output = emptystr(n+3,m); //if you really need the =====
output(1,1) = varname;
output(2:$,:) = string(matval);
// output(3:$-1,:) = string(matval);
// output([2 $],:) = "="
write_csv(output,varname+".tsv") //you should be able to open the
tsv file with excel, in a very convinient way. you can use any notepad too
endfunction
foo=rand(3,5);
//two ways to use the functions
mybetterexport foo
mybetterexport("foo");
//lets read the generated file
[ val txt] = fscanfMat ("foo.tsv") //this function will parse "foo.tsv"
very very quickly
//which allows :
function mybetterimport(varname)
[ val txt] = fscanfMat (varname+".tsv") //very useful !
if varname~=stripblanks(txt,%t) //paranoid check, you could drop
this an rely on the filename
error("file corrupted")
end
disp(varname+" will be loaded to scilab")
execstr("["+varname+"]=return(val)") //if you want to understand
this wizzard stuff, try "help execstr" and "help return", and also
http://wiki.scilab.org/howto/global%20and%20local%20variables
endfunction
clear foo //forgets foo
mybetterimport foo
mybetterimport("foo")
foo //this is total magic
--
*Adrien Vogt-Schilb*
Research Fellow
vogt at centre-cired.fr
Tel: (+33) 1 43 94 73 96
Fax: (+33) 1 43 94 73 70
CIRED
45 bis, Av de la Belle Gabrielle
F-94736 Nogent-sur-Marne
http://www.centre-cired.fr/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20110720/d56a6cae/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logocired.png
Type: image/png
Size: 4092 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20110720/d56a6cae/attachment.png>
More information about the users
mailing list