Conversion of 2000x3 decimal matrix .txt file into binary 2000x3 .txt file

2 Ansichten (letzte 30 Tage)
To begin, I have 2000x3 matrix .txt file that contains decimal numbers within, so I want to convert all decimal values to binary representation of them. How can I do that in Matlab? Thanks in advance!
e.g
6 6 13
2 6 46
4 5 10
20 30 70
10 24 182
80 44 446
19 13 940
18 9 15
60 33 16
4 28 220
2 6 46
30 26 53
16 8 98
10 24 250
18 20 512
....

Akzeptierte Antwort

Stephan
Stephan am 13 Okt. 2019
Bearbeitet: Stephan am 13 Okt. 2019
This should work:
A = readmatrix('test_input_xyz.txt');
[sz1, sz2] = size(A);
A = reshape(A,[],1);
B = sdec2bin(A,12);
B = reshape(string(B),sz1,sz2);
writematrix(B,'2_complement_values.txt','Delimiter','tab')
Note that i attached a .m-file which is needed. I loaded it down from here:
I checked one sample here:
which worked for me - but check results, since you work with a function from the web - not an inbuilt Matlab function.
  7 Kommentare
Mert Genco
Mert Genco am 13 Okt. 2019
This is it! I learned from this, really appreciated!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by