필터 지우기
필터 지우기

fprintf replace values from xlsread table

조회 수: 1 (최근 30일)
Anna Cole
Anna Cole 2018년 6월 12일
답변: Walter Roberson 2018년 6월 12일
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
Anna Cole
Anna Cole 2018년 6월 12일
eventually the column will contain 189604800 zeros but I'm just testing it now
Walter Roberson
Walter Roberson 2018년 6월 12일
How would position 101927062 be converted into an index into b ?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 6월 12일
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);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by