Incrementer une valeur dans un tableau matlab
kanwulf62
Messages postés
2
Date d'inscription
Statut
Membre
Dernière intervention
-
Char Snipeur Messages postés 9813 Date d'inscription Statut Contributeur Dernière intervention -
Char Snipeur Messages postés 9813 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
Objectif incrementer une valeur dans un tableau
Je fais la lecture du fichier excel qui se presente de la forme suivante
1 2 3 13 5 6 222 336
21 3 4 13 6 7 223 336
3 4 5 13 7 9 224 336
4 5 6 2 8 10 225 336
5 7 12 3 9 12 226 336
6 8 1 13 10 13 227 336
7 9 3 13 11 14 228 336
Quand la 4eme colonne =13
J'incremente la 7eme colonne par z=z+50
Soit 50 la premiere fois puis 100 puis 150...
Et quand la 4 eme colonne different de 1 j'increment la colonne 7 par la derniere valeur de Z.
Exemple sa donne :
1 2 3 13 5 6 272 336
21 3 4 13 6 7 323 336
3 4 5 13 7 9 374 336
4 5 6 2 8 10 375 336
5 7 12 3 9 12 376 336
6 8 1 13 10 13 427 336
7 9 3 13 11 14 478 336
Pour mon code je fais une lecture du fichier qui s'appelle fic_conso qui fonctionne.
disp(['Lecture du fichier conso: ' fic_conso])
tic
fid = fopen(fic_conso);
[tab_conso,tab_conso_dim] = fscanf(fid, ['%d/%d/%d %d:%d:%d;%d;%d'] , [8 inf]);
tab_conso_dim=tab_conso_dim/8;
disp(['dim file:' num2str(tab_conso_dim)]);
tab_conso=tab_conso';
fclose(fid);
% Calcul d'un vecteur de temps decimal pour la conso en jour julian par rapport à la
% date_ref
day_conso=datenum(tab_conso(:,3),tab_conso(:,2),tab_conso(:,1),...
tab_conso(:,4),tab_conso(:,5),tab_conso(:,6))-date_ref;
toc
et ensuite l'objectif de modifier la 7eme colonne il y a un probleme
% Variable a incrementer
z=0
% Taille du tableau pour la boucle for
[m,n]=size(tab_conso)% objectif savoir le nombre de ligne dans mon fichier excel OK apparemment
for i=1:m
if tab_conso(i,4)==13 % objectif pour la ligne correspondante je vais a la colonne 4 pas sure
z=z+50
tab_conso(i,7)= tab_conso(i,7)+z % objectif incrementer la 7eme colonne pas sure
end
if
tab_conso(i,7)= tab_conso(i,7)+z % pas sure
end
end
Ou bien repartir de 0 je ne voie pas de solution
Objectif incrementer une valeur dans un tableau
Je fais la lecture du fichier excel qui se presente de la forme suivante
1 2 3 13 5 6 222 336
21 3 4 13 6 7 223 336
3 4 5 13 7 9 224 336
4 5 6 2 8 10 225 336
5 7 12 3 9 12 226 336
6 8 1 13 10 13 227 336
7 9 3 13 11 14 228 336
Quand la 4eme colonne =13
J'incremente la 7eme colonne par z=z+50
Soit 50 la premiere fois puis 100 puis 150...
Et quand la 4 eme colonne different de 1 j'increment la colonne 7 par la derniere valeur de Z.
Exemple sa donne :
1 2 3 13 5 6 272 336
21 3 4 13 6 7 323 336
3 4 5 13 7 9 374 336
4 5 6 2 8 10 375 336
5 7 12 3 9 12 376 336
6 8 1 13 10 13 427 336
7 9 3 13 11 14 478 336
Pour mon code je fais une lecture du fichier qui s'appelle fic_conso qui fonctionne.
disp(['Lecture du fichier conso: ' fic_conso])
tic
fid = fopen(fic_conso);
[tab_conso,tab_conso_dim] = fscanf(fid, ['%d/%d/%d %d:%d:%d;%d;%d'] , [8 inf]);
tab_conso_dim=tab_conso_dim/8;
disp(['dim file:' num2str(tab_conso_dim)]);
tab_conso=tab_conso';
fclose(fid);
% Calcul d'un vecteur de temps decimal pour la conso en jour julian par rapport à la
% date_ref
day_conso=datenum(tab_conso(:,3),tab_conso(:,2),tab_conso(:,1),...
tab_conso(:,4),tab_conso(:,5),tab_conso(:,6))-date_ref;
toc
et ensuite l'objectif de modifier la 7eme colonne il y a un probleme
% Variable a incrementer
z=0
% Taille du tableau pour la boucle for
[m,n]=size(tab_conso)% objectif savoir le nombre de ligne dans mon fichier excel OK apparemment
for i=1:m
if tab_conso(i,4)==13 % objectif pour la ligne correspondante je vais a la colonne 4 pas sure
z=z+50
tab_conso(i,7)= tab_conso(i,7)+z % objectif incrementer la 7eme colonne pas sure
end
if
tab_conso(i,7)= tab_conso(i,7)+z % pas sure
end
end
Ou bien repartir de 0 je ne voie pas de solution
A voir également:
- Incrementer une valeur dans un tableau matlab
- Tableau word - Guide
- Trier un tableau excel - Guide
- Tableau ascii - Guide
- Comment imprimer un tableau excel sur une seule page - Guide
- Tableau croisé dynamique - Guide
3 réponses
for i=1:m
if tab_conso(i,4)==13
z=z+50
endif
if tab_conso(i,4)!=1
tab_conso(i,7)= tab_conso(i,7)+z
end
end
ça devrait fonctionner ça.
if tab_conso(i,4)==13
z=z+50
endif
if tab_conso(i,4)!=1
tab_conso(i,7)= tab_conso(i,7)+z
end
end
ça devrait fonctionner ça.
merci de ton aide mais j'ai finalement trouver cette solution qui fonctionne
mais maintenant je dois faire pour 2H30 et j'ai un probleme avec les IF regardez plus bas SVP
z=0
% %Taille du tableau pour la boucle for
[m,n]=size(tab_conso)
% %Seul le nombre de ligne m t'interesse.
for i=1:m
if tab_conso(i,4)==12
z=z+37;
tab_conso(i,7)= tab_conso(i,7)+z;
else
tab_conso(i,7)= tab_conso(i,7)+z;
end
end
le 2eme code avec 2H30
nous avons tab conso 4 = heure
et tab cconso 5 = minute
et tab conso 7= la valeur du tableau a incrementer
donc j'ai essayer cela mais il se passe un probleme lors du resultat
et pas de probleme niveau compilation don je fais appel a vous
tab_conso0=tab_conso;
z=0
% %Taille du tableau pour la boucle for
[m,n]=size(tab_conso)
% %Seul le nombre de ligne m t'interesse.
for i=1:m
if tab_conso(i,4)==12
z=z+37;
tab_conso(i,7)= tab_conso(i,7)+z;
end
if tab_conso(i,4)==13
z=z+37;
tab_conso(i,7)= tab_conso(i,7)+z;
end
if tab_conso(i,4)==14
if tab_conso(i,5)<30
z=z+37;
tab_conso(i,7)= tab_conso(i,7)+z;
end
else
tab_conso(i,7)= tab_conso(i,7)+z;
end
end
cordialement
mais maintenant je dois faire pour 2H30 et j'ai un probleme avec les IF regardez plus bas SVP
z=0
% %Taille du tableau pour la boucle for
[m,n]=size(tab_conso)
% %Seul le nombre de ligne m t'interesse.
for i=1:m
if tab_conso(i,4)==12
z=z+37;
tab_conso(i,7)= tab_conso(i,7)+z;
else
tab_conso(i,7)= tab_conso(i,7)+z;
end
end
le 2eme code avec 2H30
nous avons tab conso 4 = heure
et tab cconso 5 = minute
et tab conso 7= la valeur du tableau a incrementer
donc j'ai essayer cela mais il se passe un probleme lors du resultat
et pas de probleme niveau compilation don je fais appel a vous
tab_conso0=tab_conso;
z=0
% %Taille du tableau pour la boucle for
[m,n]=size(tab_conso)
% %Seul le nombre de ligne m t'interesse.
for i=1:m
if tab_conso(i,4)==12
z=z+37;
tab_conso(i,7)= tab_conso(i,7)+z;
end
if tab_conso(i,4)==13
z=z+37;
tab_conso(i,7)= tab_conso(i,7)+z;
end
if tab_conso(i,4)==14
if tab_conso(i,5)<30
z=z+37;
tab_conso(i,7)= tab_conso(i,7)+z;
end
else
tab_conso(i,7)= tab_conso(i,7)+z;
end
end
cordialement