Call fields from a struct

2 visualizaciones (últimos 30 días)
James Alix
James Alix el 14 de Oct. de 2021
Comentada: James Alix el 15 de Oct. de 2021
Hi
I'm using the tensor toolbox and within that the NMF section. I have everything working perfectly except one thing, the initialisation. It uses a struct:
% INIT : A struct containing initial values. INIT.W and INIT.H should contain
% initial values of W and H of size (m x k) and (k x n), respectively.
% When INIT is not given, W and H are randomly initialized.
I can create the 1x1 struct containing INIT.W and INIT.H of the appropriate sizes with no problem. But when I try and call it, I don't seem to be able to do.
The function looks like this within the toolbox looks like this:
params.addParamValue('init',struct([]),@(x) isstruct(x));
So, I thought it should look like this within the line undertaking the NMF:
[W,H,iter,REC]=nmf(data_nmf,k, 'MIN_ITER',500,'tol',1e-7,'method','anls_bpp','init',struct([init.W, init.H]));
I've been reading all the previous questions on structures, read the matlab pages on structures and nmf and tried lots of variations on the above....but I still don't seem to be able to run it.
I'm clearly making a really daft mistake but I just can't see it! If anyone has used this toolbox and this part of it successfully I'd be most grateful to know how you ran the initialisation.
Thanks

Respuestas (1)

Dave B
Dave B el 14 de Oct. de 2021
Editada: Dave B el 14 de Oct. de 2021
I'm a little confused, but I'll venture some guesses....
Do you have a struct init in your workspace (where you're calling the function from) with W and H fields? if so, I think you want:
[W,H,iter,REC]=nmf(data_nmf,k, 'MIN_ITER',500,'tol',1e-7,'method','anls_bpp','init',init);
Or do you have some other variable init in your workspace? If so, what is it?
If you don't have some init in your workspace, and your initial w and h were say 100 and 200:
[W,H,iter,REC]=nmf(data_nmf,k, 'MIN_ITER',500,'tol',1e-7,'method','anls_bpp','init',struct('W',100,'H',200));
that's equivalent to:
s=struct;
s.W=100;
s.H=200;
[W,H,iter,REC]=nmf(data_nmf,k, 'MIN_ITER',500,'tol',1e-7,'method','anls_bpp','init',s);
  1 comentario
James Alix
James Alix el 15 de Oct. de 2021
Hi
Thanks for replying.
I had a struct init in the workspace and so the first answer worked. Can't believe I didn't see that!
Thanks++

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by