How do i make a variable range for xlswrite?

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 Kommentare

"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
Albert Armengol am 26 Mär. 2021
But that shows me the range, but its not an input. I mean,
xlswrite(filename,A,'C1:Dn')
In the range part i cant put sprintf('C1:D%d',n)
Jan
Jan am 26 Mär. 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
Albert Armengol am 26 Mär. 2021
I understand now, it worked, thanks man

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 26 Mär. 2021
Bearbeitet: Jan am 26 Mär. 2021

0 Stimmen

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".

Gefragt:

am 26 Mär. 2021

Bearbeitet:

Jan
am 26 Mär. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by