フィルターのクリア

Read data from Excel and turn from cell into a text str

1 回表示 (過去 30 日間)
John Rebbner
John Rebbner 2018 年 12 月 14 日
編集済み: dpb 2018 年 12 月 15 日
Hi guys! I'm trying to read data from excel usign the script below.
[~,txt,raw] = xlsread('config_SCADA.xls');
.
.
.
if available_Dev == 1
start_ln=33; % data block start line
end_ln=start_ln;
for i=end_ln:length(raw(:,1));
if raw{i,1} == 1 && isnan(raw{i,1})~=1 && isempty(raw{i,1})~=1;
NameX(i,1) =(txt(i,3));
IDX(i,1)=(raw{i,4});
else
Name_Dev = {};
ID_Dev= [ ];
end
end
Name_Dev = NameX(end_ln:end);
ID_Dev = IDX(end_ln:end);
empties = find(cellfun(@isempty,Name_Dev));
Name_Dev(empties) = []; % Here I want to delete the empty cells
Name_Devss =(Name_Dev).' % Wanna transpose the data from vertical to horizontal (from a column to a row)
Name_D = Name_Devss;
class(Name_D)
And the results look like :
Name_D =
Columns 1 through 8
'XT_Ubat' 'XT_Ibat' 'XT_Ubat_min' 'XT_I_in' 'XT_P_out' 'XT_F_out' 'XT_F_in' 'XT_P_in_a'
Columns 9 through 11
'XT_P_out_a' 'XT_T_elec1' 'XT_Ubat_ond'
ans =
cell
% Now because of the not appropriate type of the data ( cell ) I want
% to convert Name_D to a text ( string, char )
...
Name_Devss =char(Name_Dev).' % Wanna transpose the data from vertical to horizontal (from a column to a row)
Name_D = Name_Devss;
class(Name_D)
%_____________________ Now you can see the results __________________________________
Name_D =
XXXXXXXXXXX
TTTTTTTTTTT
___________
UIUIPFFPPTU
bbb_______b
aaaiooiioea
tttnuunnult
_ tt _te_
m a_co
i a1n
n d
% It turns array letter by letter, All I want is to have the data in text frotmat horizontally
Help Please!
  5 件のコメント
dpb
dpb 2018 年 12 月 14 日
編集済み: dpb 2018 年 12 月 14 日
Back to the previous example:
Name={'MATE', 'GEAR', 'FIVE', 'SLOW'}; % row cellstr array
>> [Name{1} 'Someother Text'] % catenate first element to text string
ans =
'MATESomeother Text'
>> [Name{1:3} 'Someother Text'] % string elements together and same
ans =
'MATEGEARFIVESomeother Text'
You get to the content of the cellstr array by dereferencing the cell with "the curlies" instead of ordinary parentheses. Array addressing works just as for other arrays excepting by having a cell for the character array, you get the whole cellstr with one subscript instead of having to use explicit 2D array subscripting as would have to do with char arrays.
You can use other variables in lieu of the constant char string in the examples, of course, for complete generality in function.
dpb
dpb 2018 年 12 月 14 日
編集済み: dpb 2018 年 12 月 15 日
BTW, note that the orientation of the cellstr array doesn't matter here unless you use the colon in dereferencing expressions...
>> Name=Name.'
Name =
4×1 cell array
{'MATE'}
{'GEAR'}
{'FIVE'}
{'SLOW'}
>> [Name{1} ' Stuff']
ans =
'MATE Stuff'
>>
the cell content is the cell content, regardless of how the cell array itself is oriented.
>> [Name{1} ' Stuff' Name{4}]
ans =
'MATE StuffSLOW'
>>
to use two elements (or any other appropriate variable). But, if write the first example above:
>> Name{1:3}
ans =
'MATE'
ans =
'GEAR'
ans =
'FIVE'
>>
you get a comma-separated list from the column array of cell strings...note, though, that the orientation of the strings themselves in the cells isn't transposed, only the cell array itself. But, the first expression still works because the [] serve to collect the list:
>> [Name{1:3} 'Someother Text']
ans =
'MATEGEARFIVESomeother Text'
>>

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by