Azzera filtri
Azzera filtri

TXT Data Extraction Help

4 visualizzazioni (ultimi 30 giorni)
mattyice
mattyice il 21 Dic 2015
Commentato: dpb il 23 Dic 2015
Hello, I have some questions involving data abstraction from several text files.
Attached I have 3 text-files, each with two columns. In both the Loading.txt and Unloading.txt files are force and displacement data from AFM measurements. I want to extract the data from both and put them in a single 2 column matrix of force and displacement.
Then, in the Ft.txt I have time and force data. The force data have the exact same values of force as from the force displacement data. I want to extract this data, and line it up with the force displacement data, so I can get a two column time, displacement matrix. Not really sure how to go about this, since I am relatively new to Matlab.
Thanks
  1 Commento
dpb
dpb il 21 Dic 2015
Well, putting the two together isn't too tough; the problem I see is that there are multiple readings that are duplicated for the force; how was that file created vis a vis the others? It would seem there should be a known relationship a priori?

Accedi per commentare.

Risposta accettata

dpb
dpb il 22 Dic 2015
OK, had a little time to explore the data enough to figure out what appears to be going on...a simplistic way since there turns out to be only a single minimum force value--
fvt=textread('fvt.txt','','headerlines',1); % read the files; I used _much_ shorter names :)
lod=textread('loading.txt','','headerlines',1);
unlod=textread('unloading.txt','','headerlines',1);
lu=[lod(:,2);unlod(:,2)]; % concatenate the loading/unloading files (presume that order?)
At this point, I then plotted various views to get an idea what had, the most significant of which turned out to be (something you already knew :) ):
plot([fvt(:,2) lu]);
which did show the order in the two is correct and that the two force vectors do have same shape, just offset. So, given that there's a single minimum point, the easiest way to arrange them to line up on top of each other is:
[~,i1]=min(lu); % find location of minimum in the concatenated loading vector
[~,i2]=min(fvt(:,2)); % and in the time/force vector
lu=circshift(lu,i2-i1); % and make them line up with each other...
find(lu==min(lu))==find(fvt(:,2)==min(fvt(:,2))) % just make sure they do agree now...
tdisp=[fvt(:,1) lu]; % ok make a new time/displacement array from the shifted and the time
figure, plot(tdisp(:,1) tdisp(:,2)) % show what it looks like...
NB: I used the deprecated textread because it a) doesn't need the extra fopen/fclose step of textscan and returns an "ordinary" double array instead of cell array which is convenient to eliminate a couple of steps. You can use importdata or dlmread or some of the other routines for higher-level simple files as desired. I just remember textread well-enough to not think of the others much being am such an old fogey... :)
If it weren't exact match I'd follow something similar to the above with perhaps average locations or whatever. I looked at simple cross-correlation to estimate lag; over the full vector it gets smushed out so much that estimated shift was only about half that needed. If one were to take a much shorter section around the peaks alone it would likely improve the estimate significantly but since it is deterministic the fixed expression used works first time. The alternate would be useful if there were some measurement noise or similar so the two didn't precisely match identically.
  6 Commenti
mattyice
mattyice il 23 Dic 2015
Oh. I got it. Thank you so much!!
dpb
dpb il 23 Dic 2015
So, if this solved the problem, go ahead and "Accept" the answer to close the thread if nothing else.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by