How do I extract some rows in a marix that satisfy a given condition?

1 ビュー (過去 30 日間)
Stefania Avvedimento
Stefania Avvedimento 2020 年 11 月 1 日
編集済み: Mario Malic 2020 年 11 月 2 日
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!


Mario Malic
Mario Malic 2020 年 11 月 1 日
編集済み: Mario Malic 2020 年 11 月 2 日
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
Your data does not have equal number of rows, some information might be missing, you should check the files.

その他の回答 (0 件)


Find more on Tables 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!

Translated by