필터 지우기
필터 지우기

how to take out a specific row out of matrix

조회 수: 2 (최근 30일)
farfar
farfar 2018년 7월 20일
답변: Image Analyst 2018년 7월 20일
Hello I have this matrix :
a = [john 2016;john 2015;mike 2016;leo 2018]
I only need information from 2016 in second column, like:
n = [john 2016;mike 2016]
I am using this code but it does not work. any help ? Thank you !
b = [2016];
n = a(ismember(a(:,2),b),:);
  댓글 수: 9
farfar
farfar 2018년 7월 20일
편집: farfar 2018년 7월 20일
true. in the excel file, the first column is the name and the second is the numbers. but when i read it with xlsread, the matrix "a" in my workspace has only one column, (the numbers). it is not reading the names.
Image Analyst
Image Analyst 2018년 7월 20일
You do NOT have that matrix. Since your whos statement (assuming you did what James told you to do) didn't show them as variables, they're probably strings you got from Excel, which means that (the badly-named) a and n would have to be cell arrays. But the best, most modern way to do this now is with a table, something like (untested):
t = readtable(filename);
rowsToExtract = t{:, 2} == 2016
t2016 = t(rowsToExtract, :)

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2018년 7월 20일
Attach your workbook. This can probably be done with tables:
t = readtable(filename);
rowsToExtract = t{:, 2} == 2016
t2016 = t(rowsToExtract, :)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by