필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to index in an array from one cell to another cell column wise?

조회 수: 3 (최근 30일)
liu James
liu James 2016년 12월 16일
마감: MATLAB Answer Bot 2021년 8월 20일
Help, I have an array that is 1x34; however once expanded it becomes some nx6 array. I would like to loop through each column and extract the first row then loop through the columns and extract the second row.
How would you do this or is there an easy way to do this?
  댓글 수: 2
KSSV
KSSV 2016년 12월 16일
Not clear....in a cell there is n*6 matrix, what you want to extract from it? For one cell, tell me what you want to extract?
liu James
liu James 2016년 12월 16일
So basically, I will be doing comparisons between (bb{i}(s,1) > bb{i}(s,2) for each column and row. But I want it to loop back to the other columns and do the comparison row by row vs completing the full length of the first column. Does that make sense?
for i = 1:34 %% Find initial status in the portfolio: % 0 = hold nothing, 1 = Long asset, and % -1 = Short asset [status, qty1, qty2] = calcStatus(P,u,i);
%%Create an order based on Donchian Trend and holding status
caseNum = 0;
for s=1:length(bb{i})
if (status == 0) && (bb{i}(s,1) > bb{i}(s,2))
% Case 1: No holding position & Open > upper band
caseNum = 1;
bList{i} = u{i,1};
bQty{i} = Unit_Size;
elseif (status == 0) && (bb{i}(s,1) < bb{i}(s,3))
% Case 2: No holding position & Open < lower band
caseNum = 2;
sList{i} = u{i,1};
sQty{i} = Unit_Size;
end
end

답변 (1개)

KSSV
KSSV 2016년 12월 16일
clc; clear all ;
load bb.mat ;
[m,n] = size(bb) ;
for i = 1:n
k = bb{i}(:,1:2) ;
% Get bb{i}(s,1) > bb{i}(s,2) indices
idx = find(k(:,1)>k(:,2)) ;
end
I dont think the elements in first column are greater then second column in any cell.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by