Info
此问题已关闭。 请重新打开它进行编辑或回答。
Picking values from .xlsx
1 次查看(过去 30 天)
显示 更早的评论
I have a table A in the workspace (10X6), which is originally from a .xlsx file.
In the first column, which is called {'Name'}, of table A, I have the name of some objects as you can see in the following figure
In my workspace I have a (10X2) string array (B), which in the first column has the same name of first column of table A, but with two differences: they aren't in the same order and some names have a '-' in front of the name; as you can see in the following pic
I'd like to take the corresponding numbers of column 3 of the Table A and put in the second column of array B, but i can't do it because '-'
make Matlab don't recognize the string. I put the for loop i made, how can I modify my loop?
for k = 1:size(B(:,2),1)
k1 = find(string(table2array(A(:,{'Name'}))) == ...
string(B(k,1)));
RIS_V(k,2) = table2array(TENS(k1,{'u_Magnitude'}));
end
2 个评论
dpb
2020-7-25
As per usual, it would be easier to provide working code examples if had the data at hand, but...needs additional clarification first, anyways--
Are 'Bus,NNN", "-Bus,NNN", "Bus,NNN(M)" indeed all referring to the same item in the table variable A.Name?
If so, the simplest solution would probably be to turn all to a categorical() variable and create the catnames variable to coincide with the table name in the B array.
Alternatively, you can use partial string comparisons, but I think it's more of a pain to implement...
Attach A and B as .mat file containing them and folks will be able to spearmint w/ alternatives much more easily than if have to make stuff up...
Image Analyst
2020-7-25
编辑:Image Analyst
2020-7-25
Attach your workbook with the paperclip icon, and show us your call to readtable().
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!