Azzera filtri
Azzera filtri

Array Manipulation..

1 visualizzazione (ultimi 30 giorni)
Mustafa
Mustafa il 12 Lug 2011
Hi,
I have asked one question regarding a simple decrement of an array yesterday and got a good response. Today i am trying to manipulate that array further but i am kind of stuck in between loops and condtions. I am new to Matlab
It goes like this i am trying to decrement an array and once any particular element of that array arrives at zero, i am assigning that element as well as its immediate neighboring element with some value. What i need is that once that assigned value arrives at zero, it will increase the counter value by 1.
close all
clear all
clc
n = [11 12 13 24 3 7 14 11 12];
n_indx = zeros(1,12);
recv_count = 0;
send_count = 0;
send_count_1 = zeros(1,12);
recv_count_1 = zeros(1,12);
for i=1:40 % Just a loop so that the program can run for long (Not good programming practice)
while any(n)
n = max(0,n-1)
n_indx = find(n==0)
n(n_indx) = 3 ; % Assigning the value of "3" to the element that become zero
send_count_1(n_indx)=send_count+1 ; % Once an element become zero it should be recorded in this array at the same index
if (n(n_indx+1)>0) % Checking if the neighboring element is greater than zero
n(n_indx+1)=3 % Assigning the vlaue of "3" to the neighboring element
if (n(n_indx-1)>0) % Checking if the other neighboring element is also greater than zero
n(n_indx-1)=3 % Assigning the vlaue of "3" to the other neighboring element
% Now what i want is if all three elements (n_indx) && (n_indx+1)
% && (n_indx-1) are zero at the same point, they should be recorded
% into another counter
if (n(n_indx)==0) && (n(n_indx+1)==0) && (n(n_indx-1)==0)
recv_count_1(n_indx+1)=recv_count+1;
recv_count_1(n_indx-1)=recv_count+1;
% This gives me an error(That they are not scalar and i think they are scalar values).
break
end
end
end
end
end
  1 Commento
Mustafa
Mustafa il 12 Lug 2011
Sorry for poor indentation and comments.
If the array goes out of dimensions or a problem of subscript occurr, dont worry about it. I will fix that

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by