How to store Data to a text file creating two columns from two different Variables (Matrices)

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

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.

Sign in to comment.

Answers (1)

use dlmwrite ,
your_variable = [time_vector result_vector];
dlmwrite('myFile.txt',your_variable);

9 Comments

thx for your reply :)
i'm getting this massage.
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in Results (line 72) result = [A B]
it makes sense cause Size(A)=500*1 and size(B(NDT-Matrix))=1*1*500
is there any way to ake the size equal?
thx for ur reply
i'm getting the txt file but it is incorrect :(
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')
@wasa: how is it incorrect? That looks like a pretty normal CSV file.
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.
@KL. after typing data = dlmread('myFile.txt') i've noticed that the data has now two identical columns. each column has the two vectors under each other. i need those vektors to be shown as two separate columns. i don't know, where the probleme is :(
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)

Sign in to comment.

Categories

Asked:

on 20 Sep 2017

Commented:

on 8 Jun 2018

Community Treasure Hunt

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

Start Hunting!