you have 2 vectors - how do you delete the same row in both?
조회 수: 1 (최근 30일)
이전 댓글 표시
Sorry I am new to matlab and trying to learn....
Lets say we have 2 vector matrix's, Flows & FaultCodes
Flows:
12
32
56
16
98
FaultCodes (This is in one column, one cell contacts B233,B111,B222,B333 for example)
B233,B111,B222,B333
[ ]
[ ]
B212, B225, B233, B111
B786, B331, B332
- From FaultCodes I would like to delete the rows with [ ] and delete the same rows in Flows
which should give you this:
Flows:
12
16
98
FaultCodes
B233,B111,B222,B333
B212, B225, B233, B111
B786, B331, B332
2.Then, lets say I wanted to search for "B111" in FaultCodes, I would like the program to give me the value: 12 & 16 from the Flows
댓글 수: 0
답변 (1개)
Image Analyst
2021년 3월 14일
Try this:
Flows=[
12
32
56
16
98]
FaultCodes = {... % (This is in one column, one cell contacts B233,B111,B222,B333 for example)
'B233,B111,B222,B333';...
[ ];...
[ ];...
'B212, B225, B233, B111';...
'B786, B331, B332'}
% Find rows where the cell is empty
badRows = false(1, size(FaultCodes, 1));
for row = 1 : size(FaultCodes, 1)
if isempty(FaultCodes{row})
badRows(row) = true;
end
end
% Get rid of those rows
if any(badRows)
Flows(badRows) = [] % Delete rows
FaultCodes = FaultCodes(~badRows) % Another way - extract good rows.
end
You could use cellfun() if you want a shorter way to find the bad rows, but it will be more cryptic and harder to understand/follow.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dictionaries에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!