이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
manipulate matrix dimension (ignoring lines)
조회 수: 3 (최근 30일)
이전 댓글 표시
I have number of matrices sized (203*12),however Matlab doesn't read the first two lines because they are texts. Therefore, I want command to ignore these two lines for all the number of matrices resulting new matrices (201*12) in dimension.
thanks
채택된 답변
Star Strider
2018년 1월 11일
Define: 'HeaderLines',2 in the name-value pair arguments.
댓글 수: 26
Najiya Omar
2018년 1월 12일
Thank you Star Strider, the aim is to ignore these two lines not to read it
Star Strider
2018년 1월 12일
As always, my pleasure.
The 'HeaderLines',2 definition will skip the lines.
Najiya Omar
2018년 1월 12일
oh great, I used load(strcat) inside for loop, where i should apply 'Headerlines',2, or i should use textscan instead
Star Strider
2018년 1월 12일
To the best of my knowledge, the 'HeaderLines',2 name-value pair argument only works with textscan.
If your numeric matrix has 12 columns, something like this will work:
fidi = fopen( ... ); % Insert The Name Of Your File
FormatString = repmat('%f', 1, 12); % Format For Reading Numeric Data
data = textscan(fidi, FormatString, 'HeaderLines',2); % Read File
You may need to add other name-value pair arguments, depending on the requirements of your file. See the documentation on textscan for details.
Star Strider
2018년 1월 13일
I have no idea what you are doing. The code you posted makes no sense.
See the documentation for textscan that I linked to in my original Answer.
Les Beckham
2018년 1월 13일
Star is correct that your code makes no sense. You need to read some of the Matlab 'Getting Started' documentation.
I think I can see what you are trying to do, though.
Hopefully a few hints will help.
- I'm surprised you didn't get an 'Unexpected MATLAB expression' error when you defined nnew. A leading single quote does NOT create a string (char vector) like it does in Excel.
- The load command cannot be used to load text data files. Star's suggestion to use textscan is a good one.
- I suggest eliminating nnew entirely and changing your loop to for i=1:4. Then create the filename similarly to your strcat command (the part inside your load) but replacing nnew(i,:) with num2str(i). Actually, if I were doing it, I would use sprintf, but strcat should work. For example: filename = strcat(...
- Then, use Star's suggestion and use fopen and textscan (with an appropriate format spec) to read the files. Since you are doing this in a loop - reading multiple files - you will want to save the data for each file separately (I suggest using a cell array so replace data = ... with data{i} = ... in your loop). Or, you could put your plot command inside the loop (and use hold on) so you get each set of data on the same plot.
- Be sure to fclose your file at the bottom of the loop.
- Number one suggestion: read the documentation for all of the commands that Star and I have suggested. There are examples in there that will really help you understand how things are working. Also, read the documentation on using the debugger. You can step through your code and see where things are going wrong.
Good luck
Najiya Omar
2018년 1월 13일
편집: Najiya Omar
2018년 1월 13일
Hello Star and Les Beckham,
Thank you very much for your suggestions. I would like to explain my idea briefly. I recored one word for two speakers.each speaker repeated this word 10 times based on different recording time duration from 0.5 second To 5. For each time duration like 0.5s will measure different features. My aim to plot all cases of recording for speaker one with one feature and I have 5 features. So, in total, it will have 5 plots for each speakers. the lines that i want to skip are in features matrices.
Star Strider
2018년 1월 13일
‘... the lines that i want to skip are in features matrices.’
We have to know more about the file structure. We cannot guarantee that we can recover the information you want from the files that you saved.
Jan
2018년 1월 13일
@Najiya Omar: Please use flags only to inform admins and editors about postings, which might conflict with the terms of use.
If you want to say thank you, use a comment. Thanks.
Najiya Omar
2018년 1월 13일
편집: Najiya Omar
2018년 1월 13일
the matrices saved as file.dat, the two first lines are text. the size of matrix is (201*12) in dimension, after skipping the text lines will generate (199*12)
Star Strider
2018년 1월 13일
If it does not, attach one of your files to your original post or to a Comment so we can find out what the problem is.
Najiya Omar
2018년 1월 13일
I am not able to attached file.dat because this what i got Cannot attach this file because:
File format is unsupported. Use any of these formats: .bmp, .csv, .fig, .gif, .jpg, .jpeg, .m, .mlx, .mat, .mdl, .pdf, .png, .txt, .xls, .zip
Star Strider
2018년 1월 13일
Your text file ‘LPCC.m’ (that should be named ‘LPCC.txt’) can be read with:
fidi = fopen('LPCC.m', 'rt');
D = textscan(fidi, repmat('%f', 1, 13), 'HeaderLines',2, 'CollectOutput',1);
or more appropriately:
fidi = fopen('LPCC.txt', 'rt');
D = textscan(fidi, repmat('%f', 1, 13), 'HeaderLines',2, 'CollectOutput',1);
Note that there are 13 columns — not 12 — in each line.
Najiya Omar
2018년 1월 13일
편집: Najiya Omar
2018년 1월 13일
works great!!! Please accept my deepest thanks and if you don't mind might have another questions after test all files.
Najiya Omar
2018년 1월 15일
Hello star, how can I do his command in loop under different folders in different directories.
if true
data = load(strcat('C.....', filePaths(i,:) ,LPCC.dat')); end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Standard File Formats에 대해 자세히 알아보기
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
