replace character in array cell

2 vues (au cours des 30 derniers jours)
pipor
pipor le 4 Sep 2023
Commenté : pipor le 5 Sep 2023
1) [0,0,0]
2) [4,1,0.366]
if first element is >0 i want substitute the number with 'Loop'
[4,1,0.366] ====> [Loop 1** 0.366] (i want to see it in uitable)

Réponse acceptée

Voss
Voss le 4 Sep 2023
Here are a couple of guesses:
load matlab_bubu
M = vertcat(bubu{:});
idx = M(:,1) > 0;
T1 = string(M(:,1));
T1(idx) = "Loop";
T2 = string(M(:,2));
T2(idx) = T2(idx) + "**";
T = table(T1,T2,M(:,3));
disp(T);
T1 T2 Var3 ______ _____ ________ "0" "0" 0 "0" "0" 0 "Loop" "1**" 0.26538 "Loop" "1**" 0.32657 "Loop" "1**" 0.35383 "Loop" "1**" 0.3581 "Loop" "1**" 0.26178 "Loop" "1**" 0.16162 "0" "0" 0 "Loop" "1**" 0.23842 "Loop" "1**" 0.32225 "Loop" "1**" 0.24888 "Loop" "1**" 0.15602 "Loop" "1**" 0.21792 "Loop" "1**" 0.25387 "Loop" "1**" 0.22567 "Loop" "1**" 0.10702 "0" "0" 0 "0" "0" 0 "0" "0" 0 "Loop" "1**" 0.25905 "0" "0" 0 "Loop" "1**" 0.27203 "0" "0" 0 "0" "0" 0 "0" "0" 0 "0" "0" 0 "Loop" "1**" 0.22457 "0" "0" 0 "Loop" "1**" 0.23022 "0" "0" 0 "0" "0" 0 "0" "0" 0 "0" "0" 0 "Loop" "1**" 0.16852 "Loop" "1**" 0.17433 "Loop" "1**" 0.20546 "Loop" "1**" 0.16953 "Loop" "1**" 0.21737 "Loop" "1**" 0.20775 "Loop" "1**" 0.21606 "Loop" "1**" 0.15242 "Loop" "1**" 0.2982 "Loop" "1**" 0.12745 "Loop" "1**" 0.28101 "Loop" "1**" 0.15085 "Loop" "1**" 0.28145 "Loop" "1**" 0.32807 "Loop" "1**" 0.29428 "Loop" "1**" 0.076382 "0" "0" 0 "0" "0" 0 "0" "0" 0 "0" "0" 0 "Loop" "1**" 0.21402 "Loop" "1**" 0.19676 "Loop" "1**" 0.20206 "0" "0" 0 "0" "0" 0 "Loop" "1**" 0.20061 "Loop" "1**" 0.22529 "0" "0" 0 "Loop" "1**" 0.28305 "Loop" "1**" 0.25472 "Loop" "1**" 0.15076 "Loop" "1**" 0.14604 "0" "0" 0 "Loop" "1**" 0.11955 "0" "0" 0 "0" "0" 0 "Loop" "1**" 0.20162 "Loop" "1**" 0.18376 "Loop" "1**" 0.2435
T{:,1} = strcat(T{:,1}," ",T{:,2});
T = removevars(T,2);
disp(T);
T1 Var3 __________ ________ "0 0" 0 "0 0" 0 "Loop 1**" 0.26538 "Loop 1**" 0.32657 "Loop 1**" 0.35383 "Loop 1**" 0.3581 "Loop 1**" 0.26178 "Loop 1**" 0.16162 "0 0" 0 "Loop 1**" 0.23842 "Loop 1**" 0.32225 "Loop 1**" 0.24888 "Loop 1**" 0.15602 "Loop 1**" 0.21792 "Loop 1**" 0.25387 "Loop 1**" 0.22567 "Loop 1**" 0.10702 "0 0" 0 "0 0" 0 "0 0" 0 "Loop 1**" 0.25905 "0 0" 0 "Loop 1**" 0.27203 "0 0" 0 "0 0" 0 "0 0" 0 "0 0" 0 "Loop 1**" 0.22457 "0 0" 0 "Loop 1**" 0.23022 "0 0" 0 "0 0" 0 "0 0" 0 "0 0" 0 "Loop 1**" 0.16852 "Loop 1**" 0.17433 "Loop 1**" 0.20546 "Loop 1**" 0.16953 "Loop 1**" 0.21737 "Loop 1**" 0.20775 "Loop 1**" 0.21606 "Loop 1**" 0.15242 "Loop 1**" 0.2982 "Loop 1**" 0.12745 "Loop 1**" 0.28101 "Loop 1**" 0.15085 "Loop 1**" 0.28145 "Loop 1**" 0.32807 "Loop 1**" 0.29428 "Loop 1**" 0.076382 "0 0" 0 "0 0" 0 "0 0" 0 "0 0" 0 "Loop 1**" 0.21402 "Loop 1**" 0.19676 "Loop 1**" 0.20206 "0 0" 0 "0 0" 0 "Loop 1**" 0.20061 "Loop 1**" 0.22529 "0 0" 0 "Loop 1**" 0.28305 "Loop 1**" 0.25472 "Loop 1**" 0.15076 "Loop 1**" 0.14604 "0 0" 0 "Loop 1**" 0.11955 "0 0" 0 "0 0" 0 "Loop 1**" 0.20162 "Loop 1**" 0.18376 "Loop 1**" 0.2435
  1 commentaire
pipor
pipor le 5 Sep 2023
good job!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by