Info

This question is closed. Reopen it to edit or answer.

HELP? Looping and saving

1 view (last 30 days)
BOB
BOB on 19 May 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi, I would appreciate some code to assist me with the following:
I have 90 of these .cvs files:
They look like this inside (I only need the numbers from ColumnB to ColumnE and from row6 down):
I need them brought into Matlab one by one so that they can be used in these formulas:
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 Comments
Image Analyst
Image Analyst on 19 May 2014
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).
dpb
dpb on 19 May 2014
Edited: dpb on 19 May 2014
Actually, I didn't see the one I was thinking of, IA; maybe it was at cs-sm instead? I forget.

Answers (2)

dpb
dpb on 19 May 2014
Edited: dpb on 21 May 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 Comments
BOB
BOB on 19 May 2014
Hi, thanks for the response.
I didn't create the .csv viles, I just got given them.
I forgot to mention, I am a novice at matlab and don't really have much idea what I am doing.
How should I go about using textread to skip this first comma character and read the rest into an array?
dpb
dpb on 20 May 2014
Edited: dpb on 21 May 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
dpb on 20 May 2014
Edited: dpb on 20 May 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.

Products

Community Treasure Hunt

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

Start Hunting!