Finding if the current data value is greater than the previous value

48 Ansichten (letzte 30 Tage)
Nathan
Nathan am 20 Okt. 2025 um 13:04
Bearbeitet: Torsten am 20 Okt. 2025 um 13:56
I have formed a table of 1 column and many rows and I am trying to findout if the value in the current row is greater than the previous row but I am not sure where to start. I know I need to use for loops but I don't know how to use them here. Any ideas?
A= readtable ("GDF.xlsx");
for n=A
if...
Any help would be appreciated.
  2 Kommentare
Nathan
Nathan am 20 Okt. 2025 um 13:17
How would I create a link to the excel file so you can see it? The excel file is simply one column of numbers by the way if you need that information.
Torsten
Torsten am 20 Okt. 2025 um 13:24
If it's simply one column of numbers, you can use the code from below.
If this doesn't work, use the INSERT > Attachments button from the menu bar to include the file.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Torsten
Torsten am 20 Okt. 2025 um 13:11
Bearbeitet: Torsten am 20 Okt. 2025 um 13:28
It would help if you include the GDF-file.
Without further information, I'd suggest
T = readtable ("GDF.xlsx");
A = table2array(T);
DA = all(diff(A) > 0)
If DA = 0, there are rows where the current row is smaller or equal than the previous row.
If DA = 1, the column is strictly increasing in value.
  6 Kommentare
Nathan
Nathan am 20 Okt. 2025 um 13:38
I think you already answered my question I was just confused on what the code was showing and whether the data was increasing or not. Thanks for your help!
Torsten
Torsten am 20 Okt. 2025 um 13:44
Bearbeitet: Torsten am 20 Okt. 2025 um 13:56
Just to clarify again:
DA = all(diff(A) < 0)
gives logical 1 if the column is strictly decreasing throughout and gives logical 0 if there are (one or more) positions in the column where A(i+1) >= A(i).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by