how to check the value is above or below certain number in the set of columns

17 次查看(过去 30 天)
Hi,
In the attached data, from the columns 225 to 247, I need to check does any values in the row 1 exceeds 600. If exceeds, it should store value 1, otherwise 0 in the another array named say X.
Could someone help me with this?

采纳的回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023-10-10
If undestood correctly your question, logical indexing would be one of the easy solutions:
X2 = load('matlab.mat').x2;
Y = X2;
D = X2(1, 225:247);
%% Condition 1
D(D>600)=1;
X2(1, 225:247)=D; % Original X2 values are changed
X_X2 = X2(1, 225:247) %# Check the substituted values
X_X2 = 1×23
594 580 596 584 1 590 597 593 579 590 582 577 582 590 585 583 583 586 569 584 579 577 586
%% Condition 2
D = Y(1, 225:247);
D((D<600)) = 0;
D((D>600)) = 1;
X = Y;
X(1, 225:247)=D;
X_X = X(1, 225:247) %# Check the substituted values
X_X = 1×23
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
%% Put both condition findings into X2 imported original data
X2(1, 225:247)=X_X;
X2 = 2×1340
579.0000 569.0000 590.0000 577.0000 581.0000 579.0000 578.0000 575.0000 584.0000 586.0000 577.0000 583.0000 593.0000 579.0000 577.0000 583.0000 583.0000 582.0000 584.0000 580.0000 575.0000 582.0000 577.0000 585.0000 582.0000 580.0000 586.0000 577.0000 583.0000 592.0000 567.0000 567.0941 567.1882 567.2823 567.3764 567.4705 567.5646 567.6587 567.7528 567.8469 567.9410 568.0351 568.1292 568.2233 568.3174 568.4115 568.5056 568.5997 568.6938 568.7879 568.8820 568.9761 569.0702 569.1643 569.2584 569.3525 569.4466 569.5407 569.6348 569.7289

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by