現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
manipulate matrix dimension (ignoring lines)
4 ビュー (過去 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.
Najiya Omar
2018 年 1 月 12 日
sounds great, I will test and back to you Star Strider,
Thank you very much
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
Jan
2018 年 1 月 13 日
So all you have to do is to change the file extension to ".txt" or zip the file.
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.
Star Strider
2018 年 1 月 13 日
As always, my pleasure!
I will do my best to address your other questions.
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)
