Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

HELP? Looping and saving

조회 수: 1 (최근 30일)
BOB
BOB 2014년 5월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Image Analyst
Image Analyst 2014년 5월 19일
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 2014년 5월 19일
편집: dpb 2014년 5월 19일
Actually, I didn't see the one I was thinking of, IA; maybe it was at cs-sm instead? I forget.

답변 (2개)

dpb
dpb 2014년 5월 19일
편집: dpb 2014년 5월 21일
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
BOB
BOB 2014년 5월 19일
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 2014년 5월 20일
편집: dpb 2014년 5월 21일
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 2014년 5월 20일
편집: dpb 2014년 5월 20일
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.

이 질문은 마감되었습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by