sum matrixs after loading

1 visualización (últimos 30 días)
Giorgio Scolozzi
Giorgio Scolozzi el 23 de Jul. de 2012
Hi all,
I know it's a noob question and I'm sorry for that but I cannot figure it out.
This is my code:
V_I1=load('Vdef1.txt', 'V_I', '-ascii');
V_I2=load('Vdef2.txt', 'V_I', '-ascii');
V_I3=load('Vdef3.txt', 'V_I', '-ascii');
V_I4=load('Vdef4.txt', 'V_I', '-ascii');
V_I5=load('Vdef5.txt', 'V_I', '-ascii');
V_I6=load('Vdef6.txt', 'V_I', '-ascii');
V_I7=load('Vdef7.txt', 'V_I', '-ascii');
V_I8=load('Vdef8.txt', 'V_I', '-ascii');
V_I9=load('Vdef9.txt', 'V_I', '-ascii');
V_I10=load('Vdef10.txt', 'V_I', '-ascii');
for l=1:nelettrodi
for j=l+1:nelettrodi
for k=j+1:nelettrodi
V_= V_I(l)+V_I(j)+V_I(k);
I'd like V_I(j), for j=1 for example, to be the matrix V_I1 I previously loaded ( and so on for the other indexes). This way also V_ is a matrix that is the sum of the others. I searched around but I wasn't able to find the solution to this. Thanks for your help, Giorgio.

Respuestas (1)

Walter Roberson
Walter Roberson el 23 de Jul. de 2012
  2 comentarios
Giorgio Scolozzi
Giorgio Scolozzi el 24 de Jul. de 2012
Editada: Giorgio Scolozzi el 24 de Jul. de 2012
Hi walter, first of all thank you for your answer. I still have a problem with the code. As you suggested I loaded the files with a for loop,
for i=1:10
V_I=load(['Vdef',num2str(i),'.txt'], '-ascii');
but at every loop V_I is overwritten, while I need to store every file to use it later. I did this because I wasn't able to use the code in the example since my files are big matrixes and not scalars as in the example below:
textFilename = ['file' num2str(k) '.txt'];
fid = fopen(textFilename, 'rt');
textData = fread(fid);
fclose(fid);
But this doesn't bother me too much as long as I manage to make the last part work. I want V_ to be the sum of the matrix V_1 , V_2, V_3 for example. The code:
V_(i)= V_I(l)+V_I(j)+V_I(k);
does't work since I receive this error:
Undefined function 'V_I' for input
arguments of type 'double'.
and I believe is because It's not the right way to tell matlab That V_I(l) is the variable that I use for the files. I hope I made my self clear and that the answer to my problem wasn't in the pages you already sent me, in that case I apologize. Thank you again, Giorgio.
Walter Roberson
Walter Roberson el 24 de Jul. de 2012
for i=1:10
V_I{i} = load(['Vdef',num2str(i),'.txt'], '-ascii');
end
Then
V_{i} = V_I{l} + V_I{j} + V_I{k};

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by