I want to save a string with its corresponding index in a matrix but I am getting an error.
Here is a small example:
Mat_=[];
Val1=[10,19,22,15,30];
Val2=20
Strs_=[];
for i= 1:length(Val1)
if abs(Val1(1,i))<abs(Val2)
Str_={'Überschritten'};
else
Str_={'Unterschritten'};
end
Strs_=[Strs_;Str_];
Mat_=[Mat_;i];
end
Mat_
Strs_
FMat=[Mat_,Strs_]
You need a cell array to work with strings. To do this, you can preallocate a cell array and fill it.
Your
FMatcell array will be:Notice that I also changed your loop variable
itoidx. In MATLAB,iandjare defined assqrt(-1). It is always a good idea to give your variables other names.