How to show word from excel?

I want to show the word from excel. But I don't know how to show it. This is my code.
clc;
clear all;
T=readtable('EVASUSANTIDATA.xlsx');
x1=T.PENDAFTARAN;
x2=T.TUNDA;
x3=T.KUOTA;
y=T.LAMA;
For example, I want to get this result:
KOTA KUOTA LAMA
KOTA BENGKULU 311 21
it's the data number one in excel. With 'KUOTA' is 'x3' and 'LAMA' is 'y'

 Risposta accettata

Peng Li
Peng Li il 28 Mar 2020
Modificato: Peng Li il 28 Mar 2020

0 voti

subT = T(T.NO == 1, [2 5 6]);
Will be the first record with the 2nd 5th and 6th variable as a new table.

17 Commenti

Eddy Iswardi
Eddy Iswardi il 28 Mar 2020
how to show all of data?
Peng Li
Peng Li il 28 Mar 2020
T stores all your data. Could you please explain your problem a bit further?
T(T.NO == 1, :)
perhaps ?
Eddy Iswardi
Eddy Iswardi il 28 Mar 2020
At my questions, I only show an example. The example only show one data. But, Actually, I want to get result from 'KOTA BENGKULU' until the last data 'KOTA SORONG'( data 116)
T=readtable('EVASUSANTIDATA.xlsx', 'readvariablenames', false);
I get messages
Error using readtable (line 143)
An internal error occurred.
Error in ju (line 14)
T=readtable('EVASUSANTIDATA.xlsx', 'readvariablenames', false);
I will simplify my question. how to display results like this?
KOTA KUOTA LAMA
KOTA BENGKULU 311 24
KAB BENGKULU UTARA 202 12
KOTA BENGKULU SELATAN 129 16
KAB REJANG LEBONG 235 16
This is the first 4 data on Excel
T = readtable('EVASUSANTIDATA.xlsx');
T.Properties.VariableNames{2} = 'KOTA';
T(:,{'KOTA', 'KUOTA', 'LAMA'})
ans =
116×3 table
KOTA KUOTA LAMA
______________________________ _____ ____
{'KOTA BENGKULU' } 311 24
{'KAB. BENGKULU UTARA' } 202 12
{'KAB. BENGKULU SELATAN' } 129 16
{'KAB.REJANG LEBONG' } 235 16
Peng Li
Peng Li il 28 Mar 2020
T(1:4, [2 5 6]);
I guess your question is still not quite clear.
Peng Li
Peng Li il 29 Mar 2020
Use T(:, [2 5 6]) to show all rows. I thought it was easier to be generalized though. lol. btw, if you want to change the variable names, you can try Walter's way.
Eddy Iswardi
Eddy Iswardi il 29 Mar 2020
Okay. It's working now. Thank you. Peng and Walter's code.
I want to know, if I have d=[2 3 2 4], How to input 'd' to 'T(1:4, [2 5 6])'. I want to make like 'T(1:4, [2 d 6])', but it is error. I mean, the column 5 replace by d, but still have 'KUOTA' as title column.
You would want column 2 repeated multiple times? It is not possible to have two different table columns with exactly the same variable name.
Eddy Iswardi
Eddy Iswardi il 29 Mar 2020
No. I mean, 'd' is a vector. And replace column 2 with new vector as a column
Please give a sample of what you would like the result to look like.
same like my example before. only change column 2 with new vector. say that the vector is 'd'. d=[2 3 2 4]
KOTA KUOTA LAMA
KOTA BENGKULU 2 24
KAB BENGKULU UTARA 3 12
KOTA BENGKULU SELATAN 2 16
KAB REJANG LEBONG 4 16
and before like this
KOTA KUOTA LAMA
KOTA BENGKULU 311 24
KAB BENGKULU UTARA 202 12
KOTA BENGKULU SELATAN 129 16
KAB REJANG LEBONG 235 16
In the code
T(1:4, [2 5 6])
The [2 5 6] does not refer to values of KUOTA that are to be matched: the [2 5 6] refers to column numbers in the table. So when you were talking about T(1:4, [2 d 6]) then you were talking about extracting a different set of column numbers.
Anyhow:
nT = T(1:4, [2 5 6]);
nT{:,2} = d(:);
Eddy Iswardi
Eddy Iswardi il 29 Mar 2020
thanks. you guys are very helpful. now I know how to manipulate views like this in the future.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by