problem in struct

조회 수: 2 (최근 30일)
huda nawaf
huda nawaf 2012년 5월 6일
hi
I have :
x1(1:length(y),1:length(x))=0;
txt(1:length(y),1:length(x))=' ';
mat=struct('scor',x1,'pointer',txt);
mat.pointer(1,1:end)='none'
??? Subscripted assignment dimension mismatch.
how resolve this problem?

채택된 답변

Image Analyst
Image Analyst 2012년 5월 6일
First of all, y is not defined. And what is the size of mat.pointer? Set a breakpoint on the line (I know you know how to do this because you've been around here long enough), and do this:
size(mat.pointer)
If it's not a 1 row by 4 column character array, then the size of mat.pointer and 'none' don't match. And, needless to say, because you're using "end" mat.pointer must already exist, which it might because I can tell you've left out some code.
  댓글 수: 3
huda nawaf
huda nawaf 2012년 5월 6일
in fact , my problem is :
i do not want use for in my code so I converted these commands:
for j=1:length(x)
mat(1,j).scor=x1(1,j);
mat(1,j).pointer='none';
end
into:
mat(1,1:end).scor=0;
mat(1,1:end).pointer='none';
when do that get
??? Index exceeds matrix dimensions.
Error in ==> alig_waterman at 71
up_scor=mat(i-1,j).scor+gap;
where i=j=2 in this step
note:length(x)=length(y)=2
x1(1:length(y),1:length(x))=0;
txt(1:length(y),1:length(x))=' ';
mat=struct('scor',x1,'pointer',txt);
thanks in advance
Image Analyst
Image Analyst 2012년 5월 6일
I can't reproduce. I ran your code (below) and it generated no error message whatsoever.
x = 1:2; % Make some arbitrary verctor of length 2
y = 3:4; % Make some arbitrary verctor of length 2
% Note:
% length(x) = 2
% length(y) = 2
x1(1:length(y),1:length(x)) = 0
txt(1:length(y),1:length(x)) = ' '
mat = struct('scor',x1,'pointer',txt)
mat(1,1:end).scor = 0
mat(1,1:end).pointer = 'none'
Does that code produce the mat that you desire?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by