필터 지우기
필터 지우기

How to remove a row from the table?

조회 수: 14 (최근 30일)
Aswin Sandirakumaran
Aswin Sandirakumaran 2018년 6월 27일
댓글: Aswin Sandirakumaran 2018년 6월 27일
Gv = graph({'s1' 's_1' 's2' 's_2' },{'s2' 's_2','s3' 's_3'});
figure(1)
hold on
Gv.Nodes.Availability = {'null','null','null','null','null','null'}';
Gv.Nodes.Memory = [8,6,7,8,6,7]';
%Gv.Nodes.Bandwidth = [3,2,3,2,3,2]';
title('Graph representing Services & VLs');
plot(Gv);
Application = table(Gv.Nodes); % table containing the info of apps
disp(Application);
hold off
Output: Gives me a table with Name, Availability and Memory
Var1
Name Availability Memory
_______________________________
's1' 'null' 8
's2' 'null' 6
's_1' 'null' 7
's_2' 'null' 8
's3' 'null' 6
's_3' 'null' 7
How to Remove a row from the table: say how to remove s1 from the existing table?
  댓글 수: 1
Image Analyst
Image Analyst 2018년 6월 27일
This code produces a table of tables:
and each of the 6 tables has only one row.
I don't know how to answer you. Perhaps you want to reword your question, or your code.

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

채택된 답변

Adam Danz
Adam Danz 2018년 6월 27일
편집: Adam Danz 2018년 6월 27일
To remove row 1 from the table 'Application' :
Application(1,:) = []
  댓글 수: 3
Adam Danz
Adam Danz 2018년 6월 27일
편집: Adam Danz 2018년 6월 27일
First, I think you should read the comment from @Image Analyst because your table is actually a table of tables. I'm not sure what you want to do with s1 in your table.
If extracting it means isolating the s1 sub-table and storing it in another variable,
s1 = Application(1,1);
If you'd like to extract and store the 's1' from the sub-table,
s1 = Application{1,1}(1,1);
If you're trying to remove the entire s1 sub-table you can use the code I already shared above. If you're trying to remove the 's1' from the sub-table but keep the rest of that 'row' in the main table,
Application{1,1}(1,1) = table({''});
Note, you can only replace the 's1' with an empty string or {[]}. But more importantly, the table-of-tables isn't a good practice. Why do you need to assign Gv.Nodes to a new table in the first place? Why not just rename it?
Application = Gv.Nodes;
Now it's much simpler and cleaner to 'remove' (replace) 's1':
Application(1,1) = {''};
Aswin Sandirakumaran
Aswin Sandirakumaran 2018년 6월 27일
How to just print the Name of the row in the table??
Just to print say s_1 when s_1 is the first row in the table

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by