_11321
(السكروب1)
25 أبريل 2009، 12:48م
1
السلام عليكم
كمبتدىء حاولت البداية ببرمجة ترتيب اليوم في السنة وذلك لكي اجري عليها بعض الحسابات
كتبت هذا ويعطيني ان الجمل لم تكتمل
اذا اختصرتها الى شرط واحد و else تشتغل بدون مشاكل
وين الخطأ فيه
وهذا البرنامج البسيط
daydate=16;
month='March';
if month=='Januray'
month=daydate;
else if month=='Februray'
month=31+daydate;
else if month=='March'
month=59+daydate;
else if month=='April'
month=90+daydate;
else if month=='May'
month=120+daydate;
else if month=='June'
month=151+daydate;
else if month=='July'
month=181+daydate;
else if month=='August'
month=212+daydate;
else if month=='September'
month=243+daydate;
else if month=='October'
month=273+daydate;
else if month=='November'
month=304+daydate;
else if month=='Decemeber'
month=334+daydate;
end
N=month
_11321
(السكروب1)
25 أبريل 2009، 1:14م
2
حتى لو بسطتها لمثال بسيط مثل هذا يعطي نفس الخطأ
b=3;
if b>0
x=10
else if (b==0)
x=20
else
end
عندي مشكلة في if …else
_11321
(السكروب1)
25 أبريل 2009، 1:40م
3
ازلت الفراغ بين if و else
كانها تحسن حالها لكن لا يزال خطأ في
??? Error using ==> eq
Array dimensions must match for binary array op.
Error in ==> trial1 at 5
if month==‘Januray’
وعليكم السلام ورحمه الله وبركاته
انا جربت مثال بعد التبسيط
وكان الخطأ بelse if
المفروض الشرط من غير اقواس
وايضا end لل if الاولى
وكذلك لل
else if
فى الكود الاول يوجد خطأ فى المقارنه
واتوقع انه من الافضل استخدام داله strcmp
وهى لمقارنه 2 string
نفرض انه
[CENTER][B][SIZE=4][COLOR=purple]s1='eee';[/color][/size][/b]
[B][SIZE=4][COLOR=purple]s2='ggg';[/color][/size][/b]
[B][SIZE=4][COLOR=purple]c= strcmp(s1,s2)[/color][/size][/b][/center]
c راح يكون 0 او 1
اذا متطابق يكون 1
واذا لا يكون 0
ومن ثم نستخدم if لمقانه قيمه c
هذا توقعى اتمنى انه يكون صحيح
هذا تصحيح لللكود الاول
[FONT=Courier New][SIZE=2]
[SIZE=2][FONT=Courier New]daydate=16;[/font][/size]
[SIZE=2][FONT=Courier New]month=[/font][/size][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'June'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/size][/font]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Januray'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Februray'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=31+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'March'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=59+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'April'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=90+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'May'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=120+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'June'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=151+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'July'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=181+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'August'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=212+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'September'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=243+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'October'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=273+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] isequal(month,[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'November'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/size][/font]
[SIZE=2][FONT=Courier New]month=304+daydate;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] isequal(month,[/color][/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Decemeber'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/color][/size][/font]
[SIZE=2][FONT=Courier New]month=334+daydate; [/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/color][/size][/font]
[/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]disp([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'unknown month name'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/size][/font]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font]
[/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]N=month[/size][/font]
[/size][/font]
هناك طرق كثيرة لبرمجة الشي نفسه
الطريقة السابقة تؤدي الغرض ولكن احس بأنها طويلة
هذه طريقة ابسط واقل
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]
monthes={[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'January'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'February'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'March'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'April'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'May'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'June'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'July'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'August'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'September'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'October'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'November'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Decemeber'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]};
increment=[0,31,59,90,120,151,181,212,243,273,304,334];
month=[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'May'
[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]day=3
[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] i=1:length(monthes)[/color]
x=strcmp(month,monthes(i));
[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] x==1
N=day+increment(i)
[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end
end
[/color][/size][/font][/color][/size][/font][/color][/size][/font]
_11321
(السكروب1)
26 أبريل 2009، 2:45ص
9
[CENTER]فى الكود الاول يوجد خطأ فى المقارنه
واتوقع انه من الافضل استخدام داله strcmp
وهى لمقارنه 2 string
نفرض انه [/center]
[CENTER][B][SIZE=4][COLOR=purple]s1='eee';[/color][/size][/b]
[B][SIZE=4][COLOR=purple]s2='ggg';[/color][/size][/b]
[B][SIZE=4][COLOR=purple]c= strcmp(s1,s2)[/color][/size][/b][/center]
c راح يكون 0 او 1
اذا متطابق يكون 1
واذا لا يكون 0
ومن ثم نستخدم if لمقانه قيمه c
هذا توقعى اتمنى انه يكون صحيح
الله يعطيك الف عافيه ويسلموووو
انا بدلت الشهر بدل ماهو اسم بالرقم ومشي الحال
الف شكر
_11321
(السكروب1)
26 أبريل 2009، 2:58ص
10
المهندس سعود
سلمت يمينك على التعديل وماقصرت
ماهو الفرق بين == و isequal و =
انا عدلته بدل الاشهر بالارقام ومشي الحال وش الفرق؟
وانا افضل يكون بالاشهر الحرفية
بالنسبة للبرنامج الثاني الله يعطيك العافيه ماقصرت
وودي افهم بعض الاشياء
معنى
strcmp
وثالنيا لماذا وضعت الشرط x==1
وهل هناك درس او شرح مفيد في النت عن for وطريقة عملها
وانا لجأت للاول رغم طوله لقلة معرفتي بغيرة
اشكرك كثير الشكر
وتحملنا شوي واجرك على الله ان شاء تعالى
الجملة الشرطية تكتب فيها == وليس = فقط
,و== تستخدم للارقام فقط
is equal
هي للمقارنة بين كلمتين او(سترنغز)
اذا كانت متشابهة يكون الناتج 1 واذا كانت غير متشابهة يعطي الناتج صفر فلا يتحقق الشرط
strcmp
هي اختصار ل
string compare
هي للمقارن بين كلمتين اذا متشابهات يعطي واحد واذا مختلفات يعطي 0
باستخدام هذا الامر استطعت استخدام ==
فهمت
وصلت الفكرة
بالنسبة لل فور لوب
شوف الهيلب فهي سهلة ولا تحتاج للكثير من الوقت
اخي العزيز عندما تكون مشغل الماتلاب فقط اضغط F1
ستظهر عندك شاشة الهيلب
ابحث عن اي امر تريده ستجد عليه امثلة كثيرة
ولا تتردد في السؤال فنحن هنا للخدمة
_11321
(السكروب1)
27 أبريل 2009، 10:01ص
15
بيض الله وجهك ماقصرت يابطل
استفدت كثير من تعديلك ، الله يعدل لك كل مايل
الف شكر
أخى العزيز elseif تكتب هكذا بدون مسابقة
جرب البرنامج الاتى
b=3;
if b > 0
x=10
elseif (b==0)
x=20
end