Hi everyone!
I have troubles using the java.io.BufferedReader.read(char[] cbuf, int off, int len) method in MATLAB because of MATLAB's automatic conversion of Java's built-in variables (boolean, byte, short, long, int, double, float, and char) to MATLAB variables.
I can not pass a MATLAB char Array to the read method:
cbuf= =char(1:1024);
bufleng= BufferedReader.read(cbuf, 0, 1024);
Since MATLAB arrays are passed by value and any changes that a Java method makes to them are not visible to the MATLAB code. However, I need to access the changes to cbuf of the read() method.
In such a case it is suggested to creat (with MATLAB's javaArray command) a Java Array, rather than passing a MATLAB array. MATLAB's javaArray command does not support the built-in Java types and it's therefore impossible to creat a Java char array.
I bypassed this by creating a Java String Array, which I converter to a CharArray in a second step:
s= javaObject('java.lang.String', 'sdsdfsd');
charar= javaMethod('toCharArray',s)
Sadly MATLAB converts the returned Java char Array automaticlly into an MATLAB char Array.
To avoid this conversion I tried to interlace the methods in each other:
s= javaObject('java.lang.String', 'sdsdfsd');
buflen= javaMethod('read', BufferedReader, javaMethod('toCharArray',s),0,
1024);
It doesn't work either. Does somebody has a idea how to solve this problem? I would appreciate your guys help a lot!
Michael
|
|
0
|
|
|
|
Reply
|
Michael
|
12/9/2010 12:30:21 AM |
|
Hi Michael,
I think the BufferedReader cannot be used in the way you described below... It takes a Reader object... So you should try:
>> s = java.lang.String('sdsdfsd');
>> cr = java.io.CharArrayReader(s.toCharArray,0,1024);
>> br = java.io.BufferedReader(cr);
Hope this works...
Ed.
"Michael " <michael.scheidiger@hs-furtwangen.de> wrote in message <idp7ut$dai$1@fred.mathworks.com>...
> Hi everyone!
>
> I have troubles using the java.io.BufferedReader.read(char[] cbuf, int off, int len) method in MATLAB because of MATLAB's automatic conversion of Java's built-in variables (boolean, byte, short, long, int, double, float, and char) to MATLAB variables.
>
> I can not pass a MATLAB char Array to the read method:
> cbuf= =char(1:1024);
> bufleng= BufferedReader.read(cbuf, 0, 1024);
> Since MATLAB arrays are passed by value and any changes that a Java method makes to them are not visible to the MATLAB code. However, I need to access the changes to cbuf of the read() method.
>
> In such a case it is suggested to creat (with MATLAB's javaArray command) a Java Array, rather than passing a MATLAB array. MATLAB's javaArray command does not support the built-in Java types and it's therefore impossible to creat a Java char array.
>
> I bypassed this by creating a Java String Array, which I converter to a CharArray in a second step:
> s= javaObject('java.lang.String', 'sdsdfsd');
> charar= javaMethod('toCharArray',s)
> Sadly MATLAB converts the returned Java char Array automaticlly into an MATLAB char Array.
>
> To avoid this conversion I tried to interlace the methods in each other:
> s= javaObject('java.lang.String', 'sdsdfsd');
> buflen= javaMethod('read', BufferedReader, javaMethod('toCharArray',s),0,
> 1024);
>
> It doesn't work either. Does somebody has a idea how to solve this problem? I would appreciate your guys help a lot!
>
> Michael
|
|
0
|
|
|
|
Reply
|
Ed
|
12/13/2010 4:32:24 PM
|
|
Hello, I am finding exactly the same problem Michael reported, but, I'm sorry, I don't quite understand the answer given by Ed...
I need to run the read() method, but no buffer seems to have a correct formart (except cbuf= =char(1:1024); for which I can't then access the changes)
Does anyone have tryed Ed's solution or figured out how to solve the problem? I would appreciate very much. Many thanks for your help.
Alberto.
"Ed Yu" wrote in message <ie5hqo$2n7$1@fred.mathworks.com>...
> Hi Michael,
>
> I think the BufferedReader cannot be used in the way you described below... It takes a Reader object... So you should try:
>
> >> s = java.lang.String('sdsdfsd');
> >> cr = java.io.CharArrayReader(s.toCharArray,0,1024);
> >> br = java.io.BufferedReader(cr);
>
> Hope this works...
>
> Ed.
>
> "Michael " <michael.scheidiger@hs-furtwangen.de> wrote in message <idp7ut$dai$1@fred.mathworks.com>...
> > Hi everyone!
> >
> > I have troubles using the java.io.BufferedReader.read(char[] cbuf, int off, int len) method in MATLAB because of MATLAB's automatic conversion of Java's built-in variables (boolean, byte, short, long, int, double, float, and char) to MATLAB variables.
> >
> > I can not pass a MATLAB char Array to the read method:
> > cbuf= =char(1:1024);
> > bufleng= BufferedReader.read(cbuf, 0, 1024);
> > Since MATLAB arrays are passed by value and any changes that a Java method makes to them are not visible to the MATLAB code. However, I need to access the changes to cbuf of the read() method.
> >
> > In such a case it is suggested to creat (with MATLAB's javaArray command) a Java Array, rather than passing a MATLAB array. MATLAB's javaArray command does not support the built-in Java types and it's therefore impossible to creat a Java char array.
> >
> > I bypassed this by creating a Java String Array, which I converter to a CharArray in a second step:
> > s= javaObject('java.lang.String', 'sdsdfsd');
> > charar= javaMethod('toCharArray',s)
> > Sadly MATLAB converts the returned Java char Array automaticlly into an MATLAB char Array.
> >
> > To avoid this conversion I tried to interlace the methods in each other:
> > s= javaObject('java.lang.String', 'sdsdfsd');
> > buflen= javaMethod('read', BufferedReader, javaMethod('toCharArray',s),0,
> > 1024);
> >
> > It doesn't work either. Does somebody has a idea how to solve this problem? I would appreciate your guys help a lot!
> >
> > Michael
|
|
0
|
|
|
|
Reply
|
alberto.gascon (5)
|
2/3/2012 5:39:22 PM
|
|
|
2 Replies
228 Views
(page loaded in 0.275 seconds)
Similiar Articles: BufferedReader vs NIO Buffer - comp.lang.java.programmer ...... the NIO buffering faster than the IO BufferedReader ... int ix = 0; while((n = f.read(b)) >= 0) { for(int i ... fix that, you are introducing byte-to-char ... segmentation violation detected Matlab 2009b - comp.soft-sys ...... 270 bytes [15] libmwm_interpreter.dylib:inDispatchFromStack(int, char const ... Matlab Unable to Open - comp.soft-sys.matlab unable to read mex file - comp.soft-sys.matlab ... Ho to convert a logical array to a numeric array in matlab? - comp ...In Matlab, character arrays and ... MATLAB To convert characters into a numeric ... comp.soft-sys.matlab ... i have to solve this problem: how can i read *.txt file in matlab ... Open mat file with Visual C++ - comp.soft-sys.matlabI'm trying to open a mat file (Matlab v.7.7) using ... const char **dir; const char *name; int ... Visual C++ - comp.soft-sys.matlab | Computer Group Help needed: read 3 ... help with convert real value to character - comp.lang.fortran ...I know in Matlab as, "damp_char=num2str(damp)" Is ... None Real :: a Character( Len = 10 ) :: ca Read ... convert character varying to int - comp.databases ... File read failure - comp.lang.c... _flsbuf(int 69, _iobuf * 0x00477750) line 153 + 9 bytes > write_char(int 69 ... Convert .avi to .bin (binary) file - comp.soft-sys.matlab ... File read failure - comp.lang ... How to send binary or hex data in Socket using C ? - comp.unix ...Most of the SMPP types are either in 4 bytes int or char ... Reading Hex data to text. - comp.soft-sys.matlab How to ... Best way to Read BMP image and write data (in Hex) to ... simulink and arduino - comp.soft-sys.matlabI am trying to read joystick input and send ... What I want is that this int X is sent as a signle ASCII char (a single byte). ... to interact with the Arduino board using MATLAB and ... libtiff - comp.lang.fortranIn my f90 program I use a bit of C code to read and write .bmp ... like: int bmp_write ( char *fileout_name, int xsize ... image (tiff format) - comp.soft-sys.matlab converting C/Visual BASIC code to MATLAB - comp.soft-sys.matlab ...... unsigned short /* CAMERA_TYPE */ cameraType; char ... some vendor provided C and/or Visual BASIC code int= o MATLAB ... I'd have to pause to read documentation from time ... How to use BufferedReader.read(char[] , int, in... - Newsreader ...Thread Subject: How to use BufferedReader.read(char[] , int, int) with Matlab Re: How to use BufferedReader.read(char[] , int, int) with MatlabHi Michael, I think the BufferedReader cannot be used in the way you described below... It takes a Reader object... So you should try: s = java.lang.String('sdsdfsd'); 7/20/2012 2:19:03 AM
|