Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
HELP? Looping and saving
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I would appreciate some code to assist me with the following:
I have 90 of these .cvs files:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162928/image.bmp)
They look like this inside (I only need the numbers from ColumnB to ColumnE and from row6 down):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162936/image.bmp)
I need them brought into Matlab one by one so that they can be used in these formulas:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162938/image.bmp)
So Trial01 needs to go through these equations, then the graph(s) outputted and saved, before the next set of data is brought in and the same done again. Each set of data also needs to saved as a variable.
Please can anyone give me some code that can do this please. If there any any questions please don't hesitate to ask.
Thanks again
P.s Please don't point me to any other pages as I have looked round and tried and can't manage to do it
6 Commenti
Image Analyst
il 19 Mag 2014
dpb, you mean like here http://www.mathworks.com/matlabcentral/answers/?search_submit=answers&query=trial01&term=trial01.
BOB, please read over those. The file is not the flavor of CSV that MATLAB likes so you have to take special actions that are spelled out in those prior posts (which includes posts from you by the way).
Risposte (2)
dpb
il 19 Mag 2014
Modificato: dpb
il 21 Mag 2014
Anyway, BOB, how did you manage to create the .csv files that the first column is empty? The easiest solution would be to fix that problem.
To get textread to read the file you have to add the explicit delimiter keyword to let it know what to do with the leading ',' --
m{i}=textread(d(i).name,'','headerlines',5,'delimiter',',');
Alternatively, you could try importdata--on a quick test here it seemed to be able to handle the missing values returning a column of NaN in its place.
Or, use xlsread, I wasn't aware prior to now it would handle a .csv file but it was happy; skipping the first column. See doc for each of the above functions for details.
My initial response was for ease of use with a well-formed data file; as noted ADDENDUM
BTW, as IA noted, you're asking question very similar to two other posters in the file naming convention is the same and the code you show is similar in ascertaining a height from some recorded time history velocity and acceleration data it appears.
BUT, the content of the file you're showing above is totally incompatible with that assignment/processing. Looks to me like you're reading the files for a different assignment or have glommed on to the wrong piece of sample code for the data you do have.
2 Commenti
dpb
il 20 Mag 2014
Modificato: dpb
il 21 Mag 2014
Use either of the format strings I gave above. But, why must you use textread when I point out two other alternatives that could handle the problem files.
I'd tell whoever gave you the files to fix 'em...
ERRATUM:
Using the 'delimiter' option in textread to indicate the comma-delimited file is adequate.
dpb
il 20 Mag 2014
Modificato: dpb
il 20 Mag 2014
Oh, just dawned on me...
>> type bob.csv % a very short sample file I made up...
,0,7.7,11.1,-812.2
,1,8.2,11.1,-812.5
>> textread('bob.csv','','delimiter',',')
ans =
0 0 7.7000 11.1000 -812.2000
0 1.0000 8.2000 11.1000 -812.5000
Telling it the specific delimiter is the help textread needs to handle the missing column...of course, your actual file will need the proper 'headerlines' count, too.
0 Commenti
Questa domanda è chiusa.
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!