0

First Question:

regarding my code here :

for z = [1 2 4 8 12 16 24 32 64 96 128]    
    for a=1:24
        a;
        for d=1:5
            d;
           [result]=evolRand(128,1,10,1,bench);
           bb= 5*(a-1)+d;
           temp=eval(['minExe_useModel_' num2str(z)]);
           %z=num2str(zz)
           exploreff(a,d,z) =mean(mean(result(a,d).randMin(:,2:end)))/temp(bb);
        end
    end
end

why at the end I am getting :

>>size(exploreff)

ans =

    24     5   128

while I had assigned z= [1 2 4 8 12 16 24 32 64 96 128] which was 11 ??

Second Question:

How am I gonna be able to define a array of structure out of these z so that I can call them like exploreff(a,b).z ? cuz defining them like this in the script caused the

Structure assignment to non-structure object.

Error in explorationEffort_Speedup (line 15)
           exploreff(aa,dd).z=mean(mean(result(aa,dd).randMin(:,2:end)))/temp(bb);`

error.

4
  • For the first question, make sure that you do clear exploreff before the loop and check the dimension of mean(mean(result(a,d).randMin(:,2:end)))/temp(bb). Commented Mar 11, 2014 at 22:39
  • It is only 1. As it is the 2d mean Commented Mar 11, 2014 at 22:40
  • Nvm the reason that it has 128 in its last dimension is that you have 128 in the array z = [1 2 4 8 12 16 24 32 64 96 128]. Commented Mar 11, 2014 at 22:42
  • Seems so, to avoid this what should i do? Commented Mar 11, 2014 at 22:44

2 Answers 2

1

Firstly,

exploreff(a,d,z)

uses a, d and z as indices, therefore you're assigning 11 values to the 1st, 2nd, 4th, ... 96th and 128th indices along the 3rd dimension. Matlab automatically expands (and zero-fills) the array when you assign to an index outside its current dimensions, hence why the 3rd dimension ends up at 128 elements long.

Secondly, if exploreff is preallocated as a numeric array you can't just start addressing it as a structure. If you preallocate it as a struct array (using struct) first, then dynamically expanding it and adding fields in that way should be ok (I only have Octave to test, and that lets me do e.g. a(2,3).z = 5 straight off but I seem to recall Matlab wanting either the index or the field to exist first - that was 2007a though...).

Sign up to request clarification or add additional context in comments.

2 Comments

i see but what should i do to avoid this auto-assignment of zero?
and I tried exploreeff = repmat(struct ('num2str(z(1))',[], 'num2str(z(2))',[], 'num2str(z(3))',[], 'num2str(z(4))',[], 'num2str(z(5))',[], 'num2str(z(6))',[], 'num2str(z(7))',[], 'num2str(z(8))',[], 'num2str(z(9))',[], 'num2str(z(10))',[], 'num2str(z(11))',[])); but it doesn't work
1

I think this is what you want to do...

z = [1 2 4 8 12 16 24 32 64 96 128];

for i = 1:length(z)
    for a=1:24
        a;
        for d=1:5
            d;
           [result]=evolRand(128,1,10,1,bench);
           bb= 5*(a-1)+d;
           temp=eval(['minExe_useModel_' num2str(z(i))]);
           %z=num2str(zz)
           exploreff(a,d,z(i)) =mean(mean(result(a,d).randMin(:,2:end)))/temp(bb);
        end
    end
end

exploreff(a,d,z==8)

Note that z in the loop is replaced by z(i). Instead of directly specifying the value you want, you need to specify the index of the element. In the last line, z==8 specify the index of the element in vector z that has 8 value.

5 Comments

tnx for the answer, but not quit sure why the last line is outside the loop? cuz still i am having these auto-assigned zero in between the z numbers
Instead of calling exploreff(a,b).z you call something like exploreff(a,d,z==c) where c is some number in the vector z. If c is not in z you should get an empty matrix.
yes, only in this case it give am empty matrix, cuz in later steps I wanna make some other stat functions over these and I don't want these 0 affect my results
then you need to define what value you want to get out when you put some other values for z. do you want to interpolate the value over the domain of z or what?
No. Those were like discrete values as input that I used to calculate exploreff. Anyhow, i take some time to process all values z=1:128 in order to have continuous input and get rid of the issue!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.