How to store Data to a text file creating two columns from two different Variables (Matrices)
Show older comments
Hello,
I'm having a problem to create a txt.file and to store values in it. I'm reading the values from xls-file with 2 columns. The A-column represent the time (500 measuring points). so basicly i'm using the Values in the B-Column to make a calculattion. The Result of the Calclulation stored in a Vektor with 500 Values. Now i want to store the Values of the Vektor with the corrosponding time values as two Columns like the first Pic 2

. the probleme is that i'm getting the values not in two columns but in one column. first the time values und under those the measuring values like in pic 1.
fileID = fopen('result.txt','w');
fprintf(fileID,'%6.2f\r\n', Values(:,:,:));
fclose(fileID);

can someone help me please?
best regards
1 Comment
Walter Roberson
on 20 Sep 2017
Your sample output uses comma as the decimal separator. Is that important for you, or is it acceptable to use period as the separator ? '4,49E-9' compared to '4.49E-9' . The comma is more work.
Answers (1)
KL
on 20 Sep 2017
your_variable = [time_vector result_vector];
dlmwrite('myFile.txt',your_variable);
9 Comments
wasa
on 20 Sep 2017
Walter Roberson
on 20 Sep 2017
your_variable = [time_vector(:), result_vector(:)];
wasa
on 20 Sep 2017
KL
on 21 Sep 2017
It's just how notepad shows it to you. Anyway try
type('myFile.txt')
or just import and see if they are as you want them to be?
data = dlmread('myFile.txt')
Stephen23
on 21 Sep 2017
@wasa: how is it incorrect? That looks like a pretty normal CSV file.
Walter Roberson
on 21 Sep 2017
That output clearly does not have 2 columns as was requested.
The only way my suggestion
your_variable = [time_vector(:), result_vector(:)];
could have produced anything other than 2 columns would be if one or both of the variables were empty, in which case it would produce fewer columns.
wasa
on 21 Sep 2017
you said, "...Size(A)=500*1 and size(B(NDT-Matrix))=1*1*500..." and for this as Walter suggested,
your_variable = [time_vector(:), result_vector(:)]; %or [A(:), B(:)];
should only produce a two column array. What is the output for
size(your_variable) %or as you've named size(result)
Ioannis Vlachos
on 8 Jun 2018
Thank you!!
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!