dlmwrite/dlmread function help ?

I had a matrix
A = [data1 data2 data3];
B = [data4 data5];
data1,data2,....data5 are calculated or exported from excel files, these some data are randomly generated so I want to store data data2 and data4 in a matrix AA when I run it first and then run in 2nd time stored in BB. How to use dlmwrite without creating text file or creating with text file ?

댓글 수: 2

per isakson
per isakson 2017년 12월 1일
I edited the question to improve readability.
Jan
Jan 2017년 12월 1일
"How to use dlmwrite without creating text file or creating with text file": This is not clear. It is the purpose of dlmwrite to create a file, therefore it is impossible to use it without creating a file. What is the actual problem?

댓글을 달려면 로그인하십시오.

답변 (1개)

per isakson
per isakson 2017년 12월 1일
편집: per isakson 2017년 12월 1일

0 개 추천

In response to comment
This small experiment illustrates how to store a matrix to a text file and restore the matrix from the text file. In this case, there will be a precision loss, however, you may specify the precision that dlmwrite shall use.
Create a matrix
>> A = rand( 3, 5 )
A =
0.8147 0.9134 0.2785 0.9649 0.9572
0.9058 0.6324 0.5469 0.1576 0.4854
0.1270 0.0975 0.9575 0.9706 0.8003
store the matrix data to a text file
>> dlmwrite('file_with_data_of_A.txt', A )
inspect the content of the text file
>> type file_with_data_of_A.txt
0.81472,0.91338,0.2785,0.96489,0.95717
0.90579,0.63236,0.54688,0.15761,0.48538
0.12699,0.09754,0.95751,0.97059,0.80028
and finally, restore the matrix
>> B = dlmread('file_with_data_of_A.txt')
B =
0.8147 0.9134 0.2785 0.9649 0.9572
0.9058 0.6324 0.5469 0.1576 0.4854
0.1270 0.0975 0.9575 0.9706 0.8003
>>

댓글 수: 6

MUKESH KUMAR
MUKESH KUMAR 2017년 12월 1일
then how can I store those data first in text file and then use of dlmwrite ?
Jan
Jan 2017년 12월 1일
No, you do not store them in a text file and use dlmwrite afterwards. dlmwrite is the command to write the text file.
MUKESH KUMAR
MUKESH KUMAR 2017년 12월 1일
when I run program 2nd time then I want to use first run data , how is it possible then ? thanks for help
per isakson
per isakson 2017년 12월 1일
We have a communication problem.
"how can I store those data first in text file" I would rather say that dlmwrite stores the data in a text file.
Try to explain what you want to do in other words.
MUKESH KUMAR
MUKESH KUMAR 2017년 12월 1일
forget all, Lets say I have a randomly generated matrix A, now I want to store it in matrix B as text file or any suitable format and when I run program the second time then I will use the previous run data of B matrix in next equations ,each time ? Note that I dont want to save the A matrix as .mat file first.
per isakson
per isakson 2017년 12월 1일
편집: per isakson 2017년 12월 1일
See the addendum of my answer. I might have missed your intention of introducing B

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2017년 12월 1일

편집:

2017년 12월 1일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by