Editing cell array values (each cell is a matrix)
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahsan Khan
el 10 de Mayo de 2018
Comentada: Ameer Hamza
el 12 de Mayo de 2018
M=[];
M=dlmread('data.txt', '\t');
dataArray=M;
C= corrcoef(M(:,1:end));
imagesc(C);
cb = colorbar;
ylabel(cb, 'Correlation Coefficient');
moo=sqrt(C^.2)
moos=[]
for l=0:.1:1;
moo(moo<l)=0;
moos{end+1} = moo;
moos(moos>0)=1;
The last opertaion fails since > is an undefined operator for input arguments like cell. I unsuccessfully tried to make a function for the last line and implement it in cellfun. What would be the proper syntax here?
2 comentarios
Respuesta aceptada
Ameer Hamza
el 12 de Mayo de 2018
"The last operation fails since > is an undefined operator for input arguments like the cell."
You cannot directly perform the comparison on cell array. you need to access its element using curly brackets and then operate on them. For example, the following syntax will work
moos{end}(moos{end}>0) = 1;
to apply this operation to all elements of moos use cellfun as following
moos = cellfun(@(x) x.*(x<0)+(x>0)*1, moos, 'UniformOutput', 0)
2 comentarios
Ameer Hamza
el 12 de Mayo de 2018
x.*(x<0)+(x>0)*1 means that if entries are less than 0 than don't change them but if they are greater then 0, then make them 1. This is what I thought you are trying to do from your line
moos(moos>0)=1;
Más respuestas (1)
possibility
el 11 de Mayo de 2018
before starting the iteration,
mos=[];
"before starting the removal of the next mo", most probably inside-end of the iteration,
mos{l*10}=mo;
1 comentario
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!