f



matrix and text to a text file

Hi, I know some similar question have been solved before but I have been reading for a while and I didn't find the answer of my question so, I ask you.

I want to create a text-file (.txt) where I will have some text and some matrixs.
The format that i want is something like that:

-Title-
Name1.
Name2.

power(dbm):
big matrix (12000X400) aprox

frequency(hz)
vector(1x12) aprox

So, i created a m-file that can do this writing with fprintf every single character on the file using lots of for loops. It works good but if the matrix is that size it could take a time (about 7 minutes) to create the text file.

I have read about dlmwrite and I thought it was ok for me because you can put the matrix wherever you want in the text file, but before it deletes the text that it was in the file.

So, that's what I want, create a text file with some lines of text that introduces numeric matrices.

Thanks in advance,

Juanxu 
0
juanchu20 (28)
11/23/2011 12:56:11 AM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

3 Replies
1197 Views

Similar Articles

[PageSpeed] 31

"Juan Xu!" wrote in message <jahgba$csh$1@newscl01ah.mathworks.com>...
> Hi, I know some similar question have been solved before but I have been reading for a while and I didn't find the answer of my question so, I ask you.
> 
> I want to create a text-file (.txt) where I will have some text and some matrixs.
> The format that i want is something like that:
> 
> -Title-
> Name1.
> Name2.
> 
> power(dbm):
> big matrix (12000X400) aprox
> 
> frequency(hz)
> vector(1x12) aprox
> 
> So, i created a m-file that can do this writing with fprintf every single character on the file using lots of for loops. It works good but if the matrix is that size it could take a time (about 7 minutes) to create the text file.
> 
> I have read about dlmwrite and I thought it was ok for me because you can put the matrix wherever you want in the text file, but before it deletes the text that it was in the file.

Unfortunately, I think you will find that dlmwrite DOES delete the text file before it writes to it.

> 
> So, that's what I want, create a text file with some lines of text that introduces numeric matrices.
> 
> Thanks in advance,
> 
> Juanxu 
0
someone3 (1980)
11/23/2011 1:41:12 AM
On Nov 23, 1:56=A0pm, "Juan Xu! " <juanch...@hotmail.com> wrote:
> Hi, I know some similar question have been solved before but I have been =
reading for a while and I didn't find the answer of my question so, I ask y=
ou.
>
> I want to create a text-file (.txt) where I will have some text and some =
matrixs.
> The format that i want is something like that:
>
> -Title-
> Name1.
> Name2.
>
> power(dbm):
> big matrix (12000X400) aprox
>
> frequency(hz)
> vector(1x12) aprox
>
> So, i created a m-file that can do this writing with fprintf every single=
 character on the file using lots of for loops. It works good but if the ma=
trix is that size it could take a time (about 7 minutes) to create the text=
 file.
>
> I have read about dlmwrite and I thought it was ok for me because you can=
 put the matrix wherever you want in the text file, but before it deletes t=
he text that it was in the file.
>
> So, that's what I want, create a text file with some lines of text that i=
ntroduces numeric matrices.
>
> Thanks in advance,
>
> Juanxu

You should not need any loops.
If the matrix is M(12000,400), you can write it off in one fprintf
command:

fmt=3Drepmat('%f,',1,400);
fmt=3D[fmt(1:end-1) '\n'];  % remove last comma and insert LF
fprintf(fid,fmt,M');  % Note: need to transpose M
0
mulgor (3008)
11/23/2011 3:25:00 AM
thanks, now it works great!
but now, I have another question. I want to take the data from the text. So i created this program:

function [cell_data,instrumento,tipo]=text2cell(archivo)
arch=fopen(archivo,'r');
datos=textscan(arch,'%s','delimiter','\n','bufsize',50000000);%50MB
datos=datos{1};
long=length(datos);
espacio=[];
for i=1:long
    if strcmp(datos{i},'')
        espacio=[espacio i];
    end
end
num_cell=length(espacio)-1;
for i=1:num_cell
    col_cell=length(str2num(datos{espacio(i)+2}));
    format=repmat('%f',1,col_cell);
    fclose(arch);
    arch=fopen(archivo,'r');
    num=textscan(arch,format,'delimiter',',','endofline','\n',...
                 'bufsize',50000000,'headerlines',espacio(i)+1);
    matriz=[];
    for j=1:col_cell
        matriz=[matriz num{j}];
    end
    cell_data{i}=matriz;
end
instrumento=datos{1}(2:end-1);
tipo=datos{2}(2:end-1);

fclose(arch);

It works, but I guess it can be done in a better way. The variable datos has the whole text and I take from that the espaces that divide the text file into matrices and the number of columns of the matrices. Then I use textscan to take the text in '%f' format but I have to use some for loops as you can see.
So do you know a way to take the data without use for loops to create the matrix??
and other question, it is normal that i have to fclose and fopen the file any time I want to take the data from it??

Thanks!

Juanxu
0
juanchu20 (28)
11/23/2011 1:45:09 PM
Reply:

Similar Artilces:

Reading a text file into a Matlab Matrix
Hello there, I have a text file that contains the following; word11 word12 word13 word14 word21 word22 word23 word24 word31 word32 word33 word34 I want to read it into a 3x4 matrix (each word in a separate cell) I tried to use; data = textread('fileName.txt', '%s', 'delimiter', '\n') - puts each line in one cell data = textread('fileName.txt', '%s', 'delimiter', ' ') - puts each word in one cell but in a 12x1 matrix/array [col1 col2 col3 col4] = textread('tE.txt', '%s %s %s %s', 'delimit...

Reading Text File, Text Scrolling and erase line from a text file
Hi , How can I Reading Text File, then Text Scrolling by means of keys "page UP" "page Down" and erase a specific line from a text file , when press "F2" key? Best Regards, Lidia from Poland -- ========================================= Pozdrawiam Lidiaa Lidiaa schrieb: > Hi , > > How can I Reading Text File, then Text Scrolling by means of > keys "page UP" "page Down" and erase a specific line from a text > file , when press "F2" key? > > ...

inserting certain text from text file to matlab
i am using a software which outputs me a text file with 1000 lines of data. I specifically need certain lines (lets say line 100- 150), and input them into matlab. These lines actually consists of columns (lets say "X-Axis" "Y-Axis" "Z-Axis"). The first line does include the title of these columns. I want matlab to read these lines, and then using a code...generate some graphs for me. Any help would be appreciated. Anuj Anuj wrote: > i am using a software which outputs me a text file with 1000 lines of > data. I specifically need certain lines (lets say ...

writing cell containing text and matrix to a text file
Is there a way to write a cell containing text and numerical matrix to a text file? I have the following: values = [1 2 3 4 5 6 7 8 9 10]; cellA={'nameA', values};%this is the cell containing the text and matrix cellA = 'name' [1x10 double] So that the text file row would look something like: nameA 1 2 3 4 5 6 7 8 9 10 Ultimately, I would like to be able to append this with cellB, cellC, etc (all same format as shown above). I tried both dlmwrite and xlswrite without much success. Is there a way to do this? Thanks! Here is an example: ...

text + text
What is "text + text" supposed to do right now? It doesn't seem very useful to me. What about making "text + text" as an equivalent for "text || text"? Most strongly-typed programming languages do this. And MS SQL Server too, I think (CMIIW). -- dave ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org Am Freitag, 8. Oktober 2004 12:57 schrieb David Garamond: > What is "text + text" supposed to do right now? Nothing. > What a...

text-text
Wondering how what I input to my UTF-8 terminal gets passed along through my patched [1] trn ... Cyrillic: А Б В Г Д Е Ж З И Й К Л М Н О П а б в г д е ж з и й к л м н о п IPA: ᴀ ᴁ ᴂ ᴃ ᴄ ᴅ ᴆ ᴇ ᴈ ᴉ ᴊ ᴋ ᴌ ᴍ ᴎ ᴏ ɀ Ɂ ɂ Ƀ Ʉ Ʌ Ɇ ɇ Ɉ ɉ Ɋ ɋ Ɍ ɍ Ɏ ɏ [1] https://groups.google.com/d/msg/comp.sys.raspberry-pi/7Z37Hdrm0DM/6aqD-reXFzAJ ...

How to save text files in Matlab GUI from edit text box
Dear all, please help me in understanding the usage of GUI. I found on the web a suggested way to write a button callback to read the content of an edit text box and save to a txt file, that is: %save text of command.txt file fid = fopen('command.txt','wt'); fprintf(fid,'%c',get(handles.edit1,'String')) fclose(fid); Anyway, the text in the box is saved in the text file in a wrong and very peculiar way; if I write in the box something like: PALA POLO I find in the command.txt file has been saved the following: PPAOLLAO and I can't manag...

Converting A Unicode Text File to An ASCII Text File
We have a large number of text files built in Unicode that we need to be read by SAS. SAS does not read Unicode text. To convert the Unicode text to ASCII text we did the following: A Unicode text file adds an additional blank space to each character. To remove this blank character, you can use the code below. The hexidecimal value '00' is a blank character. So remove it using the SAS statement '00'x. The 'x' tells SAS you are reading hexidecimal. Use RECFM=N to tell SAS that you are reading a stream of data that will not conform to a typical file structure. SAS will ...

concatenating multiple text files into one text file
Hello all, I have a huge number of text files like : spectrum1_300_315.csv spectrum1_315_331.csv spectrum1_331_364.csv spectrum1_364_386.csv spectrum1_386_401.csv ...................................... ....................................... each file contains some headerlines at the beginning and data in 2 columns. I want to concatenate the data of the files into one text file .Can anyone hel me pls?thank u in advance. ...

Failed to write to a text file (text file is RW)
Hi, I dig up the following script. Added a simple HTML file with a form field named "vote" and have it send to the following php script. However, it failed to write to the poll_result.txt file. Why? Thanks as usual. <?php $vote = $_REQUEST['vote']; //get content of textfile $filename = "poll_result.txt"; $content = file($filename); //put content in array $array = explode("||", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 1) { $yes = $yes + 1; } if ($vote == 0) { $no = $no + 1; } // debug echo $yes; echo $no; // ou...

Text in images to a text file
Hello, Does anyone know of any software for Linux which converts text in images to a text file. I have loads of paper documents that I intend to scan. The contents of these documents needs to eventually end up on a web site but as text. Darren <bobblebob@gmail.com> wrote in message news:1151612491.407262.124690@75g2000cwc.googlegroups.com > Does anyone know of any software for Linux which converts text in > images to a text file. I have loads of paper documents that I intend > to scan. The contents of these documents needs to eventually end up > on a web site but as text....

text file not mac text
please remind me of the difference. An 8-bit prog. I have needs ASCII text. if I save a file as TEXT or simpletext on a mac, it isnt accepted. I remember 'forked files' but no details...... Is there a II utilty to 'convert' a mac text file to acceptable II ascii text? thanks. cornelio <cornelio@san.rr.com> wrote: > please remind me of the difference. An 8-bit prog. I have needs ASCII > text. if I save a file as TEXT or simpletext on a mac, it isnt accepted. > I remember 'forked files' but no details...... > > Is there a II utilty to '...

Copy text from edit text box on MATLAB GUI to specific cell on an excel file
Good day! I would like to copy or transfer the text from an edit box on MATLAB GUI (via push button) to a specific cell on an excel file. Can you suggest on how to accomplish this one or even cite sample codes? If this is not possible, can you suggest anything on how to allow the user to input texts using the MATLAB GUI (via push button) and automatically transfer the texts to a specific cell on excel? It is preferable to have the texts copied/stored to the excel file without opening the actual excel file. Thank you so much. "Mary Requilman" <maryrose.requilman@gmail....

How to format a text file just like the RFC-text files?
I want to make some document go like these, what tools can help? Any help would be nice, thanks! BLIOGRAPHY ........................................... 34 APPENDIX A. EXAMPLES ............................................... 36 B. SIMPLE FIELD PARSING ................................... 40 C. DIFFERENCES FROM RFC #733 .............................. 41 D. ALPHABETICAL LISTING OF SYNTAX RULES ................... 44 August 13, 1982 - i - RFC #822 ^L Standard for ARPA Internet Tex...

Web resources about - matrix and text to a text file - comp.soft-sys.matlab

The Matrix (franchise) - Wikipedia, the free encyclopedia
The Matrix is a science fiction action media franchise created by Andy and Larry Wachowski and distributed by Warner Bros. Pictures . The series ...

People are getting Matrix-style brain implants to boost their memory
Like something out of the Matrix, we're entering an era where it may be possible to boost your memory with a few zaps to the brain. A few dozen ...

September 2015: Unofficial Problem Bank list declines to 276 Institutions, Q3 2015 Transition Matrix
... and Anthem Bank & Trust, Plaquemine, LA ($136 million). With it being the end of the third quarter, we bring an update on the transition matrix. ...

Super Bowl special effects: New cameras power 'Matrix'-style replays
The broadcast will use a record number of cameras to capture angles that put viewers in the middle of the action.

New Film Theory Suggests Neo Isn't The One In The Matrix Trilogy
... The latest video from the Youtube channel, The Film Theorists , presents a theory that Mr. Anderson is NOT the One in the Wachowskis' The Matrix ...

Matrix-style Brain Implant Could Boost Memory
DARPA researchers want to place electrode arrays on brains to improve recall and reinforce muscle memories that don't exist.

Artificial Intelligence: What is the Matrix?
... as “dot com”. Our imaginations were running wild when at the perfect moment Warner Brothers released its science fiction classic “The Matrix”. ...

Holometer finds no evidence we’re living in a Matrix-like hologram … so far
Is our universe a two-dimensional hologram? It sounds like science fiction straight from “The Matrix,” but scientists are checking out the hypothesis ...

The Matrix Glitches as Black-and-White Comic The Walking Dead Becomes a Coloring Book
The Walking Dead comic book is a relative rarity in the world of modern, mainstream comic, as each issue is in greyscale, rather than the normal ...

LED Matrix Failure and Vindication
If necessity is the mother of invention, what’s failure the mother of? Improvement? Anyway, [prpplague]’s second version of his roll-up 70×30 ...

Resources last updated: 2/8/2016 10:49:47 AM