manipulate matrix dimension (ignoring lines)
1 次查看(过去 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
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 (한국어)
