how to create a customized array and running a counter through it?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
hello every one , i want to create an array with size A[128x4], which has A[1] consisting of only 128 elements, A[2] consisting of 32 elements, A[3] consisting of 8 elements, A[4] consisting of 2 elements, i want to run a (m = 1:256) bit counter through my array in a way that after filling my 128 elements in A[1] it goes onto fill the A[2] ..... i want to collect my output at from second element from A[4] array, it will be even better if the array shift after receiving a incremental feedback((i.e receiving on feedback as '2' the counter goes to A[2] array, receiving feedback as '3' the counter goes to the A[3] array to it an so on)). kindly guide me with it matlab, thank you.

Accepted Answer
Stephen23
on 25 Feb 2016
A = cell(1,5);
for k = 1:numel(A)
A{k} % access the kth array.
... your code
end
10 Comments
Sandeep Kumar
on 25 Feb 2016
Edited: Stephen23
on 25 Feb 2016
N= 256; %%counter size
A = cell(1,4); %% four cell arrays
for m =1:N %%counts
for k = 1:numel(A) %%incremental feedback
A((N/(4^(k-1)))/2)=0; %%when k= 1, it creates 128 bit size, for k =2 ,32bit size,
%%similarly when k =3,8bit,when k= 4, it creates 2 bit size.
A(1) = m; %%giving an input to the A[1] of the first cell
A = circshift(A,[0,-1]); %%shifting operation
output=A; %%output collecting
end
end
these are my thoughts on the code, how to make the cell shift from A[1] to A[2], after all the elements are filled in A[1]??? as shown in the figure??
A{k}
Your code is not very clear. You loop over 1:N, but never use this index m inside the loop, so only the last one is saved. It is not clear what values you want to save. It is not clear what output is, or why your completely reallocate A on every iteration.
I would suggest that instead of giving us broken code you actually show us the exact inputs and outputs that you need, with exact values and an explanation. Then we have something to write our code with, and to test it on. Broken code does not explain anything. Your explanation is what we need.
Sandeep Kumar
on 25 Feb 2016
k sure sir ill do it, where can i post the entire code here only??
Sandeep Kumar
on 25 Feb 2016
im performing a r2square single delay feedback fft., im doing it using two function programs.
Did you read my comment? I asked for an explanation of this question, not more code. Please tell us (with example numeric data) what you want to do.
Stephen23
on 25 Feb 2016
N= 16; %%counter size
A = cell(1,2); %% four cell arrays
A{1,1}(8) =0 ;
A{1,2}(2) = 0;
for k = 1:numel(A)
A{k} % access the kth array.
for m=1:16
A{1,1}(1) = m
A{1,1} = circshift(A{1,1},[0,1])
output = A{1,2}(2)
end
end
its filling only A{1,1} not going to A{1,2} after filling the A{1,1} ??
Try changing the index:
A{1,k}
I have already given you a link to the documentation about cell array indexing. Did you read it? I also gave you an example in my answer and in one of my comments. Here it is again:
A{k} % what I showed you
A{1,1} % what you used
Why did you remove the k and replace it with ones? Do you see the difference? Which of these is going to change when your loop variable k changes?
These tutorials are a good way to learn how to use MATLAB, such as how indexing works:
Sandeep Kumar
on 25 Feb 2016
working 256 bit
N= 256; %% counter size
A = cell(1,4); %% four cell arrays
A{1,1}(128) =0 ;
A{1,2}(32) = 0;
A{1,3}(8) = 0;
A{1,4}(2) = 0;
for m=1:256
A{1,1}(1) = m;
A{1,1} = circshift(A{1,1},[0,1]);
A{1,2}(1) = A{1,1}(128);
A{1,2} = circshift(A{1,2},[0,1]);
A{1,3}(1) = A{1,2}(32);
A{1,3} = circshift(A{1,3},[0,1]);
A{1,4}(1) = A{1,3}(8);
A{1,4} = circshift(A{1,4},[0,1]);
output = A{1,4}(2)
end
working 16 bit.
N= 16; %% counter size
A = cell(1,2); %% four cell arrays
A{1,1}(8) =0 ;
A{1,2}(2) = 0;
for k = 1:numel(A)
A{k} % access the kth array.
for m=1:16
A{1,1}(1) = m
A{1,1} = circshift(A{1,1},[0,1])
A{1,2}(1) = A{1,1}(8)
A{1,2} = circshift(A{1,2},[0,1])
output = A{1,2}(2)
end
end
both are working , thanku il see "A{k}" this , how it can be used in my code
Sandeep Kumar
on 25 Feb 2016
oh thanku so much sir, that is even easier to use.
Stephen23
on 25 Feb 2016
My Pleasure! You can also accept the answer the best resolves your question.
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)