Borrar filtros
Borrar filtros

fprintf replace values from xlsread table

1 visualización (últimos 30 días)
Anna Cole
Anna Cole el 12 de Jun. de 2018
Respondida: Walter Roberson el 12 de Jun. de 2018
I have a column of 100 zeroes and in certain positions in the column I want them to be replaced with a value. The position and replacement values are held inside the trial.xlsx file. What could I use to do this. Previously I was using b(positionvalue)=replacementvalue but now there are too many position values to just type them in.
b=zeros(100,1);
a = xlsread('trial.xlsx','Sheet1','A2:B1473');
c = 9 * ones(length(b),1);
c(b==0) = 1;
d=[c,b];
fileID = fopen('xlsreadtrial.txt','w');
fprintf(fileID,'%.*f\n',d');
fclose(fileID);
  5 comentarios
Anna Cole
Anna Cole el 12 de Jun. de 2018
eventually the column will contain 189604800 zeros but I'm just testing it now
Walter Roberson
Walter Roberson el 12 de Jun. de 2018
How would position 101927062 be converted into an index into b ?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Jun. de 2018
Under the assumption that the entries in column 1 are positive integers representing position, and that the number of entries might be significantly less than the maximum index, then:
b = sparse(1, a(:,1), a(:,2));
This also has the property that duplicate entries will be totaled. If you wanted them averaged instead, or want min or max of the duplicate entries, then there are relatively simple ways using accumarray().
In the case where the number of entries covers most of the maximum values, and assuming that there are no duplicate indices, then
b(a(:,1)) = a(:,2);

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by