you have 2 vectors - how do you delete the same row in both?
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Image Analyst
on 14 Mar 2021
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 Comments
See Also
Categories
Find more on Dictionaries in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!