How do I extract some rows in a marix that satisfy a given condition?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone here my data:
- a file text with the name of nodes (of a network) for example ('JUNCTION-0;JUNCTION1...') ordered by columns
- a file.mat that contains the demands of nodes
First of all I want to group the two files in a matrix/data table and then extract only the rows for which the demand is >0. The final matrix should contain only the names of junctions with the corresponding demand that satisfy the given condition. Any suggestions? I attach the two files.
Thank you!
Stefania
댓글 수: 0
채택된 답변
Mario Malic
2020년 11월 1일
편집: Mario Malic
2020년 11월 2일
Hello,
clc;
clear;
Nodi = Read_File('nodi.txt');
load demand.mat
basedemand = basedemand'; % column orientation
basedemand(end+1:length(Nodi),1) = nan; % your data does not have equal num
% of rows, filling with nans
idx = basedemand>0;
Nodes = Nodi(idx);
Demand = basedemand(idx);
T = table(Nodes,Demand)
function File_Data = Read_File(Input_File_Path)
Temp_File_Data = fileread(Input_File_Path);
File_Data (:,1) = strsplit(Temp_File_Data, newline)'; % Column-wise file orientation
end
Your data does not have equal number of rows, some information might be missing, you should check the files.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!