用该列的值替换所有列中的值 [英] replacing a value in all columns with value of that column

查看:77
本文介绍了用该列的值替换所有列中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用该列号替换ALL列中的所有1?我已经可以逐列进行操作了:

How do I replace all the 1s in ALL columns with the number of that column? I can already do it column by column:

output(output(:,3)== 1,3)= 3;
output(output(:,4)== 1,4)= 4;
output(output(:,5)== 1,5)= 5;
等等...

output(output(:,3)==1,3) = 3;
output(output(:,4)==1,4) = 4;
output(output(:,5)==1,5) = 5;
etc...

但是我觉得自己像傻瓜一样写在每一栏上.应该有一种可以一次完成所有操作的方法吗?

but I feel like a fool writing that out for every single column. There should be a way to do them all at once right?

推荐答案

您可以使用为此找到:

[rowIdx,colIdx] = find(output==1);
output(output==1) = colIdx;

这篇关于用该列的值替换所有列中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆