Comparing value in matrix in matlab

2 visualizaciones (últimos 30 días)
Chau Chin Haw
Chau Chin Haw el 22 de Dic. de 2020
Comentada: Walter Roberson el 23 de Dic. de 2020
clc;
clear;
linedata = [1 1 2 2
2 2 3 1.5
3 3 4 2.2
4 4 5 6.8
5 4 6 1
6 5 7 5.1
7 6 8 2.5
8 7 9 3.3
9 8 10 2.8
10 8 11 1.4
11 10 12 3.2
12 11 13 2.7
13 12 14 1.9
14 13 15 4.5];
bdata = [1 0
2 100
3 200
4 150
5 275
6 250
7 373
8 220
9 140
10 160
11 360
12 210
13 135
14 80
15 220];
fault = 2; %fault occur at w
row = linedata(fault,2) %bus 2 and bus 3 affected
col = linedata(fault,3)
load = bdata(row,2)+bdata(col,2)
col2 = col;
%1
row_check=find(linedata(:,2)==col)
col2 = linedata(row_check,3)
load = load+sum(bdata(col2,2))
%2
row_check=find(linedata(:,2)==col2)
col2 = linedata(row_check,3)
load = load+sum(bdata(col2,2))
%3
for i = 1:length(col2)
i
col2(i)
row_check(i)=find(linedata(:,2)==col2(i));
row_check(i)
end
col2 = linedata(row_check,3)
load = load+sum(bdata(col2,2))
%4
for i = 1:length(col2)
i
col2(i)
row_check(i)=find(linedata(:,2)==col2(i));
end
col2 = linedata(row_check,3)
load = load+sum(bdata(col2,2))
% there is an error in %4
%Unable to perform assignment because the left and right sides have a different number of elements.
%Error in test3 (line 66)
%row_check(i)=find(linedata(:,2)==col2(i));
%this error occure because row_check(i) is trying to find the value of 7 & 8 in column 2
7
8
8
%there are 2 value 8 in this column
Can someone help me to solve this?
  5 comentarios
Chau Chin Haw
Chau Chin Haw el 23 de Dic. de 2020
Hi, the any fucntion doesnt give me the right output, what i am trying to do here is finding is there is any value in column 2 is same as the value is col2(i)
%col2(i)
7
8
%column2
7
8
8
%this caused the eorror of different element to occur
Walter Roberson
Walter Roberson el 23 de Dic. de 2020
linedata(:,2) = [7;8;8]
linedata = 3×2
0 7 0 8 0 8
col2 = [7;8;9]
col2 = 3×1
7 8 9
for i = 1:length(col2)
row_check(i) = any(linedata(:,2)==col2(i));
end
row_check
row_check = 1x3 logical array
1 1 0
Looks fine to me.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by