WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Analyse .txt data with Matlab

 

qurkas_physics
Forum-Newbie

Forum-Newbie


Beiträge: 3
Anmeldedatum: 27.04.18
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 27.04.2018, 09:39     Titel: Analyse .txt data with Matlab
  Antworten mit Zitat      
Good day friends,

I have a relatively difficult task and can not continue in this regard. Therefore, I hope for the support of our strong community. I have a .txt file and would like to read and analyze it. Here is a section of the .txt file. CCCC stands for letters. XXX stands for numbers. YYYY year, MM month, DD day, HH hour, MM minute, SS second, MIS millisecond. The columns are separated by | . The first eight lines are not relevant to me. I would like to create a table with the value name in the top line and below it the numbers without name are listed. The number of data is not the same for each line. I hope the task is reasonably clear and someone can help me. Thanks in advance.

Forumpic.png
 Beschreibung:

Download
 Dateiname:  Forumpic.png
 Dateigröße:  79.21 KB
 Heruntergeladen:  646 mal
Private Nachricht senden Benutzer-Profile anzeigen


salerc
Forum-Fortgeschrittener

Forum-Fortgeschrittener


Beiträge: 51
Anmeldedatum: 23.04.18
Wohnort: ---
Version: R2021a
     Beitrag Verfasst am: 30.04.2018, 12:41     Titel:
  Antworten mit Zitat      
Hi there,

could you please specify at which point you stuck with your task?

If you want to store names and values in one structure, you should use a cell array.
For saving a textfile in a cell array you can use the function textread.
If I get you right, you want to save the value after every = . So you can use strfind to find the equal signs and the | .

Code:

C = textread('abc.txt','%s','delimiter','\n');   % read from your file (line per line)
C = C(9:end);                                    % delete the first 8 lines
loc1 = strfind(C,'=');                           % locations of all =
loc2 = strfind(C,'|');                           % locations of all |
 


Between these two locations of = and | (or after = and before the end of a line) you can find the values you want to store. Like:

Code:

str2num(C{1,1}(loc1{1}(1)+1:loc2{1}(2)-1))
 


Does that help you or do you stuck at another point?
Private Nachricht senden Benutzer-Profile anzeigen
 
qurkas_physics
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 3
Anmeldedatum: 27.04.18
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 02.05.2018, 09:36     Titel:
  Antworten mit Zitat      
Many Thanks! That was very helpfull!

But could you please explain this line a bit more:

F = str2num(C{1,1}(loc1{1}(1)+1:loc2{1}(2)-1))

it works now so that the first value is written in F for example. But i would like to realize it in a loop that takes each value and then stores it in another table.
Private Nachricht senden Benutzer-Profile anzeigen
 
salerc
Forum-Fortgeschrittener

Forum-Fortgeschrittener


Beiträge: 51
Anmeldedatum: 23.04.18
Wohnort: ---
Version: R2021a
     Beitrag Verfasst am: 02.05.2018, 12:11     Titel:
  Antworten mit Zitat      
In the cell C I stored each line of your file. So you can get line i with C{i} (or C{i,1}).

In the cell loc1 I stored the positions of each equal sign in each line, so in loc1{i} I get a vector of all positions of '=' in line i. So, to get the position j in line i I need loc1{i}(j).

To get the j-th equal sign in line i I insert that position in my cell C like: C{1,1}(loc1{1}(1)). However, I don't want the equal sign but the characters after that, so I add 1.
That would mean sth like: C{1,1}(loc1{1}(1)+1:end)

My string, which I'm interested in, ends before the |, so I do the same with loc2 and subtract 1.

It's still a string, so I need str2num to get to a number format.

Just remember there is an exception at the end of a line (there is no |), so to get the last element you need sth like loc1{i}(j)+1:end.
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.