Opening XLSX file and setting the variable type to double
이전 댓글 표시
I am working with .xlsx file and trying to get the values from it and multiply by another value(for tests, I do +1 to every cell, but it is not working as well).
This is the code I am using
Input1 = readtable('OutputFile.xlsx','sheet',2);
WorkData = Input1(17:end,[7,23:end]);
i=[1,14,27,40,53,66,79];
ValueMatrix = table2array(Input1(18:end,23:end));
GWPValues = ValueMatrix(:,i);
GWPValuesMoney = cellfun(@(x) x+1, GWPValues, 'UniformOutput', false);
But when I am trying to add 1 to every cell, it treats the cells as string rather then numeric value.
In ValueMatrix I have only numeric values and NULL

Maybe due to NULL I cannot do mathematical operations with ValueMatrix. If this is the reason how can I substitute all NULLs to 0?
채택된 답변
추가 답변 (1개)
Ankit
2019년 9월 24일
Hello Konstantin,
I have a question why don't you change the excel sheet value from NULL to 0?
Could you please give a try to below code and let me know if its work for you.
Input1 = readtable('OutputFile.xlsx','sheet',2);
WorkData = Input1(17:end,[7,23:end]);
i=[1,14,27,40,53,66,79];
ValueMatrix = table2array(Input1(18:end,23:end));
GWPValues = ValueMatrix(:,i);
tf = strcmp(GWPValues,'NULL');
GWPValues(tf) = {0} ;
GWPValuesMoney = cellfun(@(x) x+1, GWPValues, 'UniformOutput', false);
Thank you
Ankit
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!