Adding a row to an existing ones in Excel

3 vues (au cours des 30 derniers jours)
Cristian Martin
Cristian Martin le 4 Juin 2022
Commenté : Cristian Martin le 4 Juin 2022
Hi guys,
I have to write some data to an excel after getting them from an edit text and from a column of an uitable
tableDatanew = get(handles.uitable4, 'data');
tableDatacoloane = cell2table(tableDatanew);
tableDatacoloane1 = tableDatacoloane{1,2:2};% taking the date
date = char(tableDatacoloane1);
intrari_a = get(handles.edit3,'String');% taking a number
intrari_b = get(handles.edit4,'String');% taking a number
intrari_c = get(handles.edit5,'String');% taking a number
total = get(handles.edit2,'String');% taking a number
grafic1 = {date intrari_a intrari_b intrari_c total};
%disp(grafic1);
%'01.02.2021' '1' '3' '2' '6'
grafic2 = readtable('grafic\grafic.xlsx');%read old datas from tables
new_data = [grafic2; grafic1];%combining new and old
writetable(new_data, 'grafic\grafic.xlsx','Sheet',1,'Range','A2','WriteVariableNames',0);
%For the first input in excel display(new_data) looks like this:
A B C D E
____________ ___ ___ ___ ___
'01.02.2021' '1' '3' '2' '6'
%For the second input in excel display(new_data) looks like this:
A B C D E
____________ ___ ___ ___ ___
'01.02.2021' [1] [3] [2] [6]
'01.02.2021' '1' '3' '2' '6'
%the problem i guess is somewere in tableread variable B to E ....
%For the third input in excel error is this:
Cannot concatenate the table variable 'B' because it is a cell in one table and a non-cell in another.
  1 commentaire
Cristian Martin
Cristian Martin le 4 Juin 2022
The problem was from not converting the edittext values to double
intrari_a = str2double(get(handles.edit3,'String'));
intrari_b = str2double(get(handles.edit4,'String'));
intrari_c = str2double(get(handles.edit5,'String'));
total = str2double(get(handles.edit2,'String'));

Connectez-vous pour commenter.

Réponses (1)

Benjamin Thompson
Benjamin Thompson le 4 Juin 2022
I cannot review online documentation for releases earlier than R2017A, but in that release readtable supports a 'TextType' option to convert input strings as 'char' or 'string'. Or try the 'Format' option if you want to read in from Excel as numbers. Either way you need to get the data types you read in from Excel to match what you are reading in from your UI so that the table concatenation will work.
  1 commentaire
Cristian Martin
Cristian Martin le 4 Juin 2022
I solved the problem, thanks Benjamin!

Connectez-vous pour commenter.

Produits


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by