Remove certain elements from a matrix
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a text file Pressure which has a lot of rows and two columns and I want to remove the rows and columns where the columns are equal to zero, and display the old graph and new graph on the same plot and this is what i have so far, I don't know what to put in the if statement.
% Copy data from Pressure to OldData
OldData = load('Pressure.txt');
% Copy OldData to NewData
NewData = OldData;
% Remove points where there are zeros
for i = 1:length(OldData)
if(OldData(i,2) == 0)
end
end
% Plot both in same plot:
plot(OldData(:,1),OldData(:,2),'--b',NewData(:,1),NewData(:,2), 'r')
1 comentario
Azzi Abdelmalek
el 15 de Abr. de 2016
Make your Question clear. Avoid details that are not important to resolve your problem. You can post a short example with expected result
Respuestas (2)
James Tursa
el 15 de Abr. de 2016
Editada: James Tursa
el 15 de Abr. de 2016
Replace this:
% Remove points where there are zeros
for i = 1:length(OldData)
if(OldData(i,2) == 0)
end
end
with this:
% Remove points where there are zeros
x = OldData(:,2)==0; % Logical indexes where column 2 is 0
NewData(x,:) = []; % Remove the rows where column 2 is 0
0 comentarios
Roger Stafford
el 16 de Abr. de 2016
Or you just write:
NewData = OldData(OldData(:,2)==0,:);
0 comentarios
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!