Filter löschen
Filter löschen

Load txt file and split into the matrix

1 Ansicht (letzte 30 Tage)
Dominik Cech
Dominik Cech am 4 Sep. 2021
Bearbeitet: Stephen23 am 4 Sep. 2021
hello i have a txt file that i want to load and then it makes me 139x2 matrix then I chose data what i want and i makes me 121x1 matrix
clear all;
A=readtable('_cl_data_draha_nastroje2.txt')
B=A(19:139,2)
{'-9.4925,78.2355,49.0974,-0.5710247,0.7637159,0.3011125' }
{'-10.1414,78.2525,48.7282,-0.5694185,0.7634438,0.3048215' }
{'-10.7290,78.2728,48.3698,-0.5677140,0.7632457,0.3084751' }
{'-11.5366,78.3085,47.8449,-0.5650385,0.7630117,0.3139182' }
{'-12.2915,78.3486,47.3231,-0.5622776,0.7627737,0.3194060' }
{'-13.0160,78.3952,46.7976,-0.5595119,0.7624675,0.3249458' }
{'-13.7227,78.4474,46.2607,-0.5567769,0.7620374,0.3306032' }
{'-14.4119,78.5063,45.7151,-0.5541024,0.7614721,0.3363493' }
{'-15.0816,78.5713,45.1651,-0.5514732,0.7607848,0.3421750' }
{'-15.7296,78.6410,44.6150,-0.5488955,0.7599623,0.3480964' }
{'-16.3575,78.7147,44.0686,-0.5463235,0.7590584,0.3540636' }
{'-16.9692,78.7914,43.5245,-0.5437513,0.7580590,0.3601127' }
{'-17.5673,78.8709,42.9845,-0.5411592,0.7569990,0.3661956' }
{'-18.7357,79.0367,41.9120,-0.5359051,0.7546881,0.3784859' }
this is a part of B matrix and i have six values on each row and i would like to make two C and D 121x3 matrix
that will look like this C=[-9.4925, 78.2355, 49.0974; -10.1414,78, etc]
D=[-0.5710247, 0.7637159, ,0.3011125;-0.5694185, etc]
I would be glad for any help, thank you
  1 Kommentar
Stephen23
Stephen23 am 4 Sep. 2021
Bearbeitet: Stephen23 am 4 Sep. 2021
It looks like the importing did not work very well.
Most likely you should improve the importing with appropriate options/commands, rather than messing around with text.
Please upload a sample file by clicking on the paperclip button.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Chunru
Chunru am 4 Sep. 2021
B = {'-9.4925,78.2355,49.0974,-0.5710247,0.7637159,0.3011125'
'-10.1414,78.2525,48.7282,-0.5694185,0.7634438,0.3048215'
'-10.7290,78.2728,48.3698,-0.5677140,0.7632457,0.3084751'
'-11.5366,78.3085,47.8449,-0.5650385,0.7630117,0.3139182'
'-12.2915,78.3486,47.3231,-0.5622776,0.7627737,0.3194060' } ; % part of original B
B = str2double(split(string(B), ','))
B = 5×6
-9.4925 78.2355 49.0974 -0.5710 0.7637 0.3011 -10.1414 78.2525 48.7282 -0.5694 0.7634 0.3048 -10.7290 78.2728 48.3698 -0.5677 0.7632 0.3085 -11.5366 78.3085 47.8449 -0.5650 0.7630 0.3139 -12.2915 78.3486 47.3231 -0.5623 0.7628 0.3194
C = B(:, 1:3)
C = 5×3
-9.4925 78.2355 49.0974 -10.1414 78.2525 48.7282 -10.7290 78.2728 48.3698 -11.5366 78.3085 47.8449 -12.2915 78.3486 47.3231
D = B(:, 4:6)
D = 5×3
-0.5710 0.7637 0.3011 -0.5694 0.7634 0.3048 -0.5677 0.7632 0.3085 -0.5650 0.7630 0.3139 -0.5623 0.7628 0.3194

Kategorien

Mehr zu Characters and Strings 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!

Translated by