이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
reading in text files
댓글 수: 14
I need 250 separate files that are 7909x10 doubles after entering. Doing the above loop I get 1 7909x34 double. I am just looking how to get these all in and then create another loop to reduce those data sets to the 250 individual files that have the data from columns 1,2,3 and 6 for all the 250 files I am importing.
You're only getting one file because you're overwriting M each time you read the next file. You need to index M. I would suggest using cell arrays.
M(k) = {dlmread(textFilename,' ',1,0)};
That combined them so I can see all 250 files so thank you. However, it is still creating a file much larger than the .txt file. the .txt file is originally 7909x10. The code creates a 1x250 cell which works but inside the cell the 250 data sets are 7909x34 doubles. Is there anyway to keep that 1x250 cell and extract only the columns that I need out of each individual 7909x34 double and create another 1x250 cell?
To the best of my knowledge dlmread(), or any importer command besides xlsread(), cannot import only specific columns. You're going to need to import then entire thing and then redefine the matrix to only include the desired columns. This can be done in a new matrix, or by just redefining the old.
M{k} = M{k}(:,[1,2,3,6]); % Reshape original, all data outside of columns % 1,2,3, and 6 will be lost N{k} = M{k}(:,[1,2,3,6]); % Make a new matrix, keep all of the original % data in M for later use
Awesome! thank you. Once I have done that I need to correct the two middle by a set value for each point, essentially normalizing them. I have tried something along the lines of
M(k) = {dlmread(textFilename,' ',1,0)}; N{k} = M{k}(:,[1,2,3,6]); T{k} = M{k}(:,[1,2+10000,3+10000,6]);
but that just moves those cells 10000 values higher, correct?
Anything contained within the parentheses following an array is the indexing. Using [1,2+10000,3+10000,6] is still specifying a location, so it will look for columns 1, 6, 10002, and 10003. If you want to just add values then you need to do so outside of the indexing operation.
T{k}(:,[1,4]) = M{k}(:,[1,6]); T{k}(:,[2,3]) = M{k}(:,[2,3]) + 10000;
Yes, it is possible to sort things based on specific values of rows. Going back to our previous example:
T{k} = T{k}(T{k}(:,4)==4||T{k}(:,4)==9||T{k}(:,4)==12||T{k}(:,4)==15||T{k}(:,4)==17,:); % Note that this removes all other values of T{k}. If you want to keep them % you need to save them as a different variable. Also note that all of the % right side of the equation is indexing, there is no value adjustment.
Basically, you can include logic challenges in your indexing.
답변 (1개)
댓글 수: 8
dinfo = 'C58501_line_ssF_%04d.txt'; pathToFiles = {dinfo.name};
ds = tabularTextDatastore(pathToFiles) ds.SelectedVariableNames = ds.SelectedVariableNames([1,2,3,6]);
while hasdata(ds) T = read(ds) % do stuff end
This returns an error of 'Struct contents reference from a non-struct array object'. Coming from the line
pathToFiles = {dinfo.name};
참고 항목
카테고리
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 (한국어)