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!