MATLAB: How to Scale Array Indices to larger array indices

arrayMATLABscaling

Okay, suppose I have logical/TTL square wave array that looks something like this.
t = [0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0];
It is a scaled down representation of a much larger array with a 1:68608 scaling. I.e. here value 2 is at index 2 but in the larger array index 2 would start at 68608 + 1
I need to get the scaled indices of all the 0 and 1 sections for indexing the larger array. What I have been doing so far is getting the edge indices using strfind(t, [0 1]) and strfind(t, [1 0]) and multiplying them by the scaling factor to get the correct scaled indices for the edges and then some stuff with find(cumsum()) to get inclusive indices which gets me close by I am usually missing a unit or so because this wont include edges.
I just need a way to mathematically scale these indices. So instead of 6:10 and 16:20 I have 343041:686080 and 1029121:1372160 but in a way that will also include edges if for example I needed 1:5, 11:15, and 21 in which case 21 wouldn't just be 21 but 1372161:1440768.
Which has been the pit fall of my cum sum method so far as 21 just scales to 21 and doesnt give me a range except 21:21.
Edit to add a software example (ignore redunant logic, this was something I was playing with):
function [idx, numVals] = giveIndices(t)
valsPerUnit = 100;
numVals = valsPerUnit*numel(t);
starts = strfind(t, [0 1]);
stops = strfind(t, [1 0]);%+1;

if stops(1) < starts(1)
starts = [1 starts+1];
if starts(end) > stops(end)
if starts(end) < numel(t)
stops(end+1) = numel(t);%+1;
else
stops(end+1) = numel(t);
end
else
end
starts = starts*valsPerUnit;
starts = starts-(valsPerUnit-1);
stops = stops*valsPerUnit+1;
k = [];
k(starts) = -1;
k(stops) = 1;
idx = find(cumsum(k));
else
starts = starts*valsPerUnit+1;
stops = stops*valsPerUnit+1;
k = [];
k(starts) = -1;
k(stops) = 1;
idx = find(cumsum(k));
end
end
This will give you the correct indices for most circumstance but not always. For example this will work if t = [0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0] & t= [1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1], but will fail for t = [0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1] because it wont get the ends.

Best Answer

Here is one simple approach based on diff and find. Because a scaling factor of 68608 is rather inconvenient I used a scaling factor of 3.
>> t = [0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0]; % small vector.
>> k = 3; % scaling factor: large/small.
>> D = diff([false,t==1,false]); % small detect 1's.
>> B = k*(find(D>0)-1)+1 % large begin of 1's.

B =
16 46
>> E = k*(find(D<0)-2)+k % large end of 1's.

E =
30 60
Check these against the large vector, for integer scaling factors we can use repelem or kron, e.g.:
>> z = kron(t,ones(1,k)) % large vector.
z =
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0
>> D = diff([false,z==1,false]); % large detect 1's.
>> find(D>0) % large begin of 1's.
ans =
16 46
>> find(D<0)-1 % large end of 1's.
ans =
30 60
Detecting the 0's I leave as a simple exercise for the reader.