Hello!
When I want to change a cell in a matrix with the original value NULL into 'C', the 'C' turns into the value 67. This is my code:
for j=1:99
percentage2 = j/99
mDataTest(m,1) = str2double(data{1}{j});
mDataTest(m,2) = 0;
for i = 3:50
percentage1 = j/50
if(strcmp(data{i}{j},''))
mDataTest(m,i) = 'C';
elseif(strcmp(data{i}{j},'NULL'))
mDataTest(m,i) = 'C' ;
else
mDataTest(m,i) = str2double(data{i}{j}); %make matrix with data
end
end
m=m+1;
n=3;
end
Where data is a matrix filled with strings and numeric values. The goal of this is to change all values that are '' or 'NULL' into a string. Eventually I want to replace all 'C' with the median of that vector. Can someone help me?

 채택된 답변

Matt J
Matt J 2018년 7월 3일
편집: Matt J 2018년 7월 3일

0 개 추천

If you don't want mDataTest to be double, then don't use str2double when you create it.

댓글 수: 4

I only want to change the NULL and the '' into 'C' but the rest can change into a double. Is my function correct?
It is not possible to assign both numeric and characters to the same array except by using cell array.
Matt J
Matt J 2018년 7월 3일
편집: Matt J 2018년 7월 3일
This might be what you want. As Walter says, mDataTest must be kept as type cell array.
for j=1:99
percentage2 = j/99
mDataTest{m,2} = 0;
for i = 3:50
percentage1 = j/50
if(strcmp(data{i}{j},'') || strcmp(data{i}{j},'NULL'))
mDataTest{m,i} = 'C';
else
mDataTest{m,i} = str2double(data{i}{j});
end
end
m=m+1;
n=3;
end
It works! Thank you very much!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2015b

태그

Community Treasure Hunt

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

Start Hunting!

Translated by