Create a new .dat file by editing an existing one
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
Iv'e got a .dat file and I would like to edit it by removing some elements in the mid of the columns and adding zeros in the beggining and end of it. I used the folowing lines to enter the exisitng .dat file and then create a new one
data_in = dlmread('old_data.dat');
data_out = [data_in(:,1), data_in(:,2), data_in(:,3)];
save new_data.dat data_out -ASCII
How can we remove elements from some points of the 'old_data.dat' and add zeros in some other, so that the 'new_data.dat ' will have the same size with the first/exisitng one?
Any help would be greatly appreciated.
8 Kommentare
per isakson
am 26 Nov. 2019
I cannot understand where you found the values
[6,2,2,3,3,1]
that you have assigned to the third column.
And "two values of 3rd column, 7 and 1, and added 2 zeros instead" is hard to interpret given your required matrix.
Anyhow "given your example can you modify M so that you eventulay get the following"
%% My example
M = [
9 9 4
9 6 6
5 1 2
8 8 7
2 9 1
4 7 3
9 7 1
8 7 1 ];
%%
M(2:7,3) = reshape( [6,2,2,3,3,1], [],1 );
M([1,8],3) = 0;
disp(M)
displays
9 9 0
9 6 6
5 1 2
8 8 2
2 9 3
4 7 3
9 7 1
8 7 0
which is identical to your required matrix of the previous comment. (In your previous example you shuffled the rows in a way that I failed to understand.)
Before trying to make useful code you need to
- learn the very basics of Matlab. Spend a couple of hours with Learn the essentials of MATLAB® through this free, two-hour introductory tutorial on commonly used features and workflows.
- get an overwiev of the documentation. You need to use it all the time. See MATLAB The Language of Technical Computing
Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!