Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to find Y value that corresponds to the maximum X value in these graphs?

1 vue (au cours des 30 derniers jours)
Ismail Qeshta
Ismail Qeshta le 18 Fév 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi,
I need to find the Y value that corresponds to the maximum X value for the curves attached herewith.
I tried to use interp1, but I am not sure how to make it for several files.
Can anyone please help me with this?
Thank you.
  5 commentaires
Ismail Qeshta
Ismail Qeshta le 19 Fév 2019
Modifié(e) : Ismail Qeshta le 19 Fév 2019
Hi Bob,
I tried to develop this code, but it does not work.
I get the following error message:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in ResidualDisp (line 10)
maxy = matDrift(max(matDrift(:,1)),2);
clear; clc;
Folder = cd;
N=10;
for k = 1:N;
Driftt = sprintf('X%d.out', k);
matDrift = importdata(fullfile(Folder, Driftt));
maxy = matDrift(max(matDrift(:,1)),2);
end

Réponses (1)

KSSV
KSSV le 19 Fév 2019
files = dir('*.txt') ;
N = length(files) ;
iwant = zeros(N,2) ;
for i = 1:N
data = load(files(i).name) ;
[val,idx] = max(data(:,1)) ;
iwant(i,:) = [val data(idx,2)] ;
end
  8 commentaires
Ismail Qeshta
Ismail Qeshta le 19 Fév 2019
Hi KSSV,
Thank you for your suggestion.
I am not sure, I have used it as below, but it still does not work.
The updated code:
files = dir('*.out') ;
N = length(files) ;
iwant = zeros(N,2) ;
for i = 1:N
data = load(files(i).name) ;
[val,idx] = sort_nat((max(data(:,1))));
iwant(i,:) =[val data(idx,2)];
end

Cette question est clôturée.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by