How do i make a variable range for xlswrite?
Show older comments
i need a program that can read a variable range, this program can run until the same excel cell is already fill, i dont want that, ex. if i have a variable, lets say
n=3
i want the range to be:
C1:Dn
n being the variable but of course i cant put that bc it expects a number
filename = 'test.xlsx'
A = xlsread(filename,2,'A2')
Vmin = A * 0.95
Vmax = A*1.05
B = xlsread(filename,6,'B2:B99')
size = numel(B)
for n=1:size
L = B(n)
if(L<=Vmin)
A={'YES'}
xlswrite(filename,A,6,'F2:F99')
B={'CAPACITIVO'}
xlswrite(filename,A,6,'G2:G99')
elseif(L>=Vmax)
A={'YES'}
xlswrite(filename,A,6,'F2:F99')
B = {'INDUCTIVO'}
xlswrite(filename,A,6,'G2:G99')
else
A={'NO'}
xlswrite(filename,A,6,'F2:F99')
endif
endfor
4 Comments
Jan
on 26 Mar 2021
"endfor" and "endif" are not Matlab commands. If you use Octave, it is useful to mention this.
Do you mean:
sprintf('C1:D%d', n)
Albert Armengol
on 26 Mar 2021
Jan
on 26 Mar 2021
I do not understand, what you are asking for.
"In the range part i cant put sprintf('C1:D%d',n)" - Why not?
Albert Armengol
on 26 Mar 2021
Answers (1)
Range = sprintf('C1:D%d', n);
xlswrite(filename,A, Range)
By the way, there are many submissions in the FileExchange to create the strange notations for larger indices in Excel like e.g. "AAB2".
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!