what is the easiest way to reduce the lines in the code below?
조회 수: 1 (최근 30일)
이전 댓글 표시
I need to read every row but certain column in the csv file. Does anyone know how to modify the code below?
File = csvread('flowrate.csv');
1 = File(:,1)
2 = File(:,2)
3 = File(:,3)
4 = File(:,4)
5 = File(:,5)
7 = File(:,7)
8 = File(:,8)
9 = File(:,9)
10 = File(:,10)
11 = File(:,11)
Thanks in advance
댓글 수: 0
채택된 답변
dpb
2020년 11월 24일
data=csvread('flowrate.csv');
% Solution 1: Eliminate unwanted column
data(:,6)=[];
% Solution 2: Keep desired columns
data=data(:,[1:5 7:11]);
댓글 수: 3
dpb
2020년 11월 24일
편집: dpb
2020년 11월 24일
I don't what to tell you other than to read the explanations and see the general principles behind the examples. The <Array indexing> link at the bottom of the above page starts off with "there are three primary approaches to accessing array elements based on their location (index) in the array. These approaches are indexing by position, linear indexing, and logical indexing."
This is followed by a section on each of the three techniques where in the first section is the information that for multiple elements you can "reference multiple elements at a time by specifying their indices in a vector." and the example of that as r = A(2,[1 3])
It then continues directly thereafter with "To access elements in a range of rows or columns, use the colon." and an example for that syntax as well, r = A(1:3,2:4).
Those are some of the basic principles of MATLAB syntax; they apply to any general indexing situation where you know the numeric value of the desired indices.
As far as the [], see the link <Removing Rows or Columns from a Matrix> also at the bottom of the page to which I pointed you before.
As said, you simply must spend some time reading the doc and assimilating the general rules that are explained; there's no substitute for that effort.
There's an OnRamp training course many apparently find helpful; I don't have the direct link to it; I'm certain a search for the term should find it for you.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!