Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
I need help, I have xlswrite row problems
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
The first picture (excel.PNG) is what my data looks like using xlswrite, the second picture (instructions.PNG) is what it is supposed to look like. Here is the code I used to display it, I know I am not displaying it correctly to the correct cells because I am using n as the cell number. There are 32 games and I am only supposed to display home games so the number of the game doesn't correspond with the number of the cell I am supposed to put it in. Also the data, such as the numbers, are wrong due to using the n as the cell number as well.
% data
home = 'vs';
for n = 1:sRows
if strcmp(home, headers{n, 1}) == 1
date = [stats(n, 1), stats(n, 2), stats(n, 3)];
opponent = headers{n, 2};
pointsAU = stats(n, 4);
pointsOpp = stats(n, 5);
attend = stats(n, 6);
cellDate = sprintf('A%d', n);
cellOpp = sprintf('B%d', n);
cellPointsAU = sprintf('C%d', n);
cellPointsOpp = sprintf('D%d', n);
cellAttend = sprintf('E%d', n);
OPPONENT = sprintf('%s', opponent);
DATE = sprintf('%d/%d/%d', date);
xlswrite(FILENAME, {DATE}, OUTSPREADSHEET, cellDate)
xlswrite(FILENAME, {OPPONENT}, OUTSPREADSHEET, cellOpp)
xlswrite(FILENAME, pointsAU, OUTSPREADSHEET, cellPointsAU)
xlswrite(FILENAME, pointsOpp, OUTSPREADSHEET, cellPointsOpp)
xlswrite(FILENAME, attend, OUTSPREADSHEET, cellAttend)
end
end
0 Commenti
Risposte (1)
Geoff Hayes
il 16 Apr 2019
Matthew - the row problem can be handled by using a different variable (other than n) to determine where the next row should be. Something like
% data
home = 'vs';
insertRowAt = 1;
for n = 1:sRows
if strcmp(home, headers{n, 1}) == 1
% your code
% code to insert data at cell
cellDate = sprintf('A%d', insertRowAt);
cellOpp = sprintf('B%d', insertRowAt);
cellPointsAU = sprintf('C%d', insertRowAt);
cellPointsOpp = sprintf('D%d', insertRowAt);
cellAttend = sprintf('E%d', insertRowAt);
insertRowAt = insertRowAt + 1;
% your other code
end
end
The above might fix the problem with all of the blank lines in your output. However, for the other problem of not showing the correct game... I don't understand how the
if strcmp(home, headers{n, 1}) == 1
condition is supposed to work since home is initialized to 'vs'. What is headers{n, 1} as a string? Why are you comparing this to 'vs' and assuming that this is a home game?
3 Commenti
Geoff Hayes
il 16 Apr 2019
so how is the incorrect game data being shown then? are you sure that the data in headers and stats correspond correctly between the rows?
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!