help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Matrix assignment question


From: Nir Krakauer
Subject: Matrix assignment question
Date: Wed, 20 Feb 2013 16:00:50 -0500

If I have

A = ones(2);
X = [2 NaN; NaN 3];

and I want to update A to reflect the values in X (excluding missing
values), I can do

i = isfinite(X);
A(i) = X(i);

However, if X only corresponds to a part of the matrix I want to
update, this become more complicated. If

B = ones(3);

the following expression is illegal:

B(1:2, 1:2)(i) = X(i);

In order to update B, I need to do something like

tmp = zeros(size(B), "logical");
tmp(1:2, 1:2) = i;
B(tmp) = X(i);

Anyone know of a more elegant way to accomplish this?

Best,

Nir


reply via email to

[Prev in Thread] Current Thread [Next in Thread]