我有一个有两列(没有标题)的单元格矩阵。第一列包含股票代码,例如AAPL,GS等。第二列包含0或1。
如何删除第2列中包含“1”的所有行?那么如何在不同的m文件中单独输出剩余的股票代码?
请帮忙!
答案 0 :(得分:1)
这可以满足您的需求吗?
>> a = {'AAPL', 1; 'MSFT', 0; 'GOOG' 1; 'IBM', 0} % Make some data like the OP's
a =
'AAPL' [1]
'MSFT' [0]
'GOOG' [1]
'IBM' [0]
>> toDelete = cell2mat(a(:,2)) == 1; % Extract which rows have a 1 in column 2
>> a(toDelete,:) = []; % Delete those rows
>> remainingTickers = a(:,1) % Extract column 1 from the remaining rows
remainingTickers =
'MSFT'
'IBM'